diff_test 0.8.9 → 0.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0eb6d31f88ec71845c1da318d944b46bcb0d7c6b550b0bb9c936a4236cd4e802
4
- data.tar.gz: 879e45fa217f327c095c4f1bccac3d7308df661a3735ba3a549cdc8550c4360c
3
+ metadata.gz: d36a2feba28342c37ee92d44d615a9466f17824cffc14992c4031901d3035c2b
4
+ data.tar.gz: 75996211c6e3f6ba9942c201e3c12ec5b2c0031ebbb4052e11a82ebf3b7a2307
5
5
  SHA512:
6
- metadata.gz: d935e9d4ebce09151f96d998b9aa7cfcd4adc3f8a5e45622b29e1e57a093184b39e98321392eab581b37c2a7b51f8927bbb99fb4df447896ced3f3e409868b3f
7
- data.tar.gz: cf82343110711249ec65a56486a559ae899614e886f49faceea1c35020abc58758f438a87969db609f866171abe5228421e7e23f12fcd9170689cbe1c8e40580
6
+ metadata.gz: 54fed90750ebe5ab28d7cf81568401f5db7db5b9fd341538eef0f23403255cf1891c3a3795696d207c59b15fbb5f6b965063a8c5a5d968e54722e36b48b66fba
7
+ data.tar.gz: bfd6d8d252b80a9769465e6879c36d91613c3998fa9f0f71d0fbfcde5c79a83e9da9fb40a392a74bf572eaf0fe1b6f3d73a39ab9c7ffc7dcd196b9cce95dc60c
data/README.md CHANGED
@@ -253,3 +253,6 @@ test/services/zoom_webhook_event_processor_test.rb
253
253
 
254
254
  overhead of const TracePoint and file path prefix native
255
255
  method_added/const_added
256
+
257
+
258
+ # WRITE test for it setting time from previous successful run
@@ -74,5 +74,9 @@ module DiffTest
74
74
  puts "Finished #{name.join(' ')} in #{(Time.now - start).round(2)}s------------"
75
75
  result
76
76
  end
77
+
78
+ def log(message)
79
+ puts "DiffTest #{Time.current.strftime('%H:%M:%S')}: #{message}"
80
+ end
77
81
  end
78
82
  end
@@ -4,6 +4,16 @@ module DiffTest
4
4
  module Lifecycle
5
5
  def self.included(base)
6
6
  base.prepend(InstanceMethods)
7
+
8
+ require 'get_process_mem'
9
+ Thread.new do
10
+ mem = GetProcessMem.new
11
+ loop do
12
+ # `mem.mb` returns the resident set size as a Float in megabytes
13
+ DiffTest::Helper.log("Memory: #{format('%8.2f MB', mem.mb)}")
14
+ sleep 1
15
+ end
16
+ end
7
17
  end
8
18
 
9
19
  module InstanceMethods
@@ -55,7 +65,7 @@ module DiffTest
55
65
  test_name = self.name
56
66
 
57
67
  DiffTest::TestExecution.current = execution = DiffTest::TestExecution.new(test_file_path:, test_name:)
58
- should_run = DiffTest::ShouldRunDecider.should_run?(execution.id, system_test: true)
68
+ should_run = execution.should_run?
59
69
  DiffTest::TestSuiteExecution.current.ensure_application_eager_loaded! if should_run
60
70
  rescue => e
61
71
  DiffTest.error("An error ocurred while trying to create a test execution. Please report this issue.\nException: #{e}")
@@ -67,11 +77,10 @@ module DiffTest
67
77
  super
68
78
  else
69
79
  # Skip raises an exception too, which is handled by `capture_exception`
70
- time_it do
71
- capture_exceptions do
72
- skip("Impacted files have not changed. Skipping...")
73
- end
80
+ capture_exceptions do
81
+ skip("Impacted files have not changed. Skipping...")
74
82
  end
83
+ self.time = execution.previous_runtime_s
75
84
  ::Minitest::Result.from(self)
76
85
  end
77
86
  ensure
@@ -34,7 +34,7 @@ module DiffTest
34
34
  insert_at_first_non_comment_line_str(content, annotation)
35
35
  end
36
36
 
37
- UNANNOTATE_REGEX = /(\/\/|#) Automatically added by DiffTest.*?(\/\/|#) Automatically added by DiffTest\n/m
37
+ UNANNOTATE_REGEX = /(\/\/|#) Automatically added by DiffTest.*?(\/\/|#) Automatically added by DiffTest\n\n?/m
38
38
  def self.unannotate(content)
39
39
  content.gsub!(UNANNOTATE_REGEX, '')
40
40
  content
@@ -8,9 +8,10 @@ module DiffTest
8
8
  end
9
9
 
10
10
  def should_run?(test_id, system_test:)
11
- return true unless @test_executions_by_test
11
+ return { should_run: true } unless @test_executions_by_test
12
12
 
13
13
  previous_test_executions = @test_executions_by_test[test_id] || []
14
+ previous_runtime_ms = nil
14
15
 
15
16
  # If there are any previous test executions run whose impacted files are the same as now
16
17
  # Assume its safe to skip
@@ -23,6 +24,8 @@ module DiffTest
23
24
  DiffTest::FileHashComputer.compute_relative(impacted_file_path) == file_hash
24
25
  end
25
26
  next false unless hashes_match
27
+
28
+ previous_runtime_ms = previous_test_execution['runtime_ms']
26
29
  next true unless system_test
27
30
 
28
31
  test_suite_execution = @test_suite_executions_by_id[previous_test_execution['test_suite_execution_id'].to_s]
@@ -32,8 +35,13 @@ module DiffTest
32
35
  false
33
36
  end
34
37
 
35
- return true if ENV['DIFF_TEST_ALWAYS_RUN'] == '1'
36
- !has_previous_execution_with_no_impacted_changes
38
+ return { should_run: true } if ENV['DIFF_TEST_ALWAYS_RUN'] == '1'
39
+
40
+ should_run = !has_previous_execution_with_no_impacted_changes
41
+ {
42
+ should_run:,
43
+ previous_runtime_ms:,
44
+ }
37
45
  end
38
46
 
39
47
  def self.current
@@ -13,9 +13,16 @@ module DiffTest
13
13
  self.class.set(id, self)
14
14
  end
15
15
 
16
+ def should_run_decider_result
17
+ @should_run_decider_result ||= DiffTest::ShouldRunDecider.should_run?(id, system_test: system_test?)
18
+ end
19
+
16
20
  def should_run?
17
- return @should_run unless @should_run.nil?
18
- @should_run = DiffTest::ShouldRunDecider.should_run?(id, system_test: system_test?)
21
+ should_run_decider_result[:should_run]
22
+ end
23
+
24
+ def previous_runtime_s
25
+ (should_run_decider_result[:previous_runtime_ms] / 1000.0) if should_run_decider_result[:previous_runtime_ms]
19
26
  end
20
27
 
21
28
  def save_payload
@@ -23,7 +30,7 @@ module DiffTest
23
30
  test: id,
24
31
  result: @result,
25
32
  runtime_ms: runtime_ms,
26
- impacted_files: (@impacted_file_tracker.save_payload if passed?),
33
+ impacted_files: (@impacted_file_tracker.save_payload if successful?),
27
34
  }.compact
28
35
  end
29
36
 
@@ -32,6 +39,7 @@ module DiffTest
32
39
  end
33
40
 
34
41
  def start
42
+ DiffTest::Helper.log("TestExecution.start: #{id}")
35
43
  @impacted_file_tracker.start
36
44
  @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
37
45
  end
@@ -39,6 +47,7 @@ module DiffTest
39
47
  def stop
40
48
  @impacted_file_tracker.stop
41
49
  @stopped_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50
+ DiffTest::Helper.log("TestExecution.stop: #{id}")
42
51
  finish
43
52
  end
44
53
 
@@ -66,6 +75,14 @@ module DiffTest
66
75
  @result == :passed
67
76
  end
68
77
 
78
+ def skipped?
79
+ @result == :skipped
80
+ end
81
+
82
+ def successful?
83
+ passed? || skipped?
84
+ end
85
+
69
86
  def runtime_ms
70
87
  return 0 if @stopped_at.nil? || @started_at.nil?
71
88
  (@stopped_at - @started_at) * 1000
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiffTest
4
- VERSION = "0.8.9"
4
+ VERSION = "0.8.11"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-28 00:00:00.000000000 Z
11
+ date: 2025-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty