diff_test 0.8.9 → 0.8.12

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: 572fb4d96758c15f33fb86d759208c20707bc041e86bd41846ad3fb25e7878bc
4
+ data.tar.gz: 58be1a6c50f15d51ee35c867f9f82351e027f11391e80a00236a72084935c64d
5
5
  SHA512:
6
- metadata.gz: d935e9d4ebce09151f96d998b9aa7cfcd4adc3f8a5e45622b29e1e57a093184b39e98321392eab581b37c2a7b51f8927bbb99fb4df447896ced3f3e409868b3f
7
- data.tar.gz: cf82343110711249ec65a56486a559ae899614e886f49faceea1c35020abc58758f438a87969db609f866171abe5228421e7e23f12fcd9170689cbe1c8e40580
6
+ metadata.gz: 3d127f58c88c7e5d05a0af258fda8f1e553f98f2e17c1ca7b5d079f620a769211ca62b5e0e6d9ac1fbb0a44624f3af7c2c2bda947d6cbd8a072d55edf802584e
7
+ data.tar.gz: 296d9ddcff60b4958d90ecdd4f7acf1b7402af66fd4f73c23d392efe22dc4ab3bb2f721bb1c404619f91b69889e4a5ad4fe0b2295d77fdd545b586fe0c00a7c7
data/README.md CHANGED
@@ -253,3 +253,22 @@ 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
259
+
260
+
261
+
262
+ # Perf improvements
263
+
264
+ # TestExecution
265
+ # - New Test table (just for test name)
266
+ # - Drop updated_at
267
+ # - impacted_file_hash becomes integer
268
+
269
+ # ImpactedFile
270
+ - add file_path and file_hash
271
+
272
+ # TestExecutionImpactedFile
273
+ - Store file hash with impacted file
274
+ - TestExecutionImpactedFile then just belongs to test execution and impacted_file
@@ -11,7 +11,7 @@ module DiffTest
11
11
  content = DiffTest::Integrations::RailsJs::Annotator.unannotate(content)
12
12
 
13
13
  @cache ||= {}
14
- @cache[file_path] = XXhash.xxh64(content).to_s
14
+ @cache[file_path] = XXhash.xxh32(content).to_s
15
15
  end
16
16
 
17
17
  def self.compute_relative(file_path)
@@ -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}" if ENV['DIFF_TEST_LOG']
80
+ end
77
81
  end
78
82
  end
@@ -55,7 +55,7 @@ module DiffTest
55
55
  test_name = self.name
56
56
 
57
57
  DiffTest::TestExecution.current = execution = DiffTest::TestExecution.new(test_file_path:, test_name:)
58
- should_run = DiffTest::ShouldRunDecider.should_run?(execution.id, system_test: true)
58
+ should_run = execution.should_run?
59
59
  DiffTest::TestSuiteExecution.current.ensure_application_eager_loaded! if should_run
60
60
  rescue => e
61
61
  DiffTest.error("An error ocurred while trying to create a test execution. Please report this issue.\nException: #{e}")
@@ -67,11 +67,10 @@ module DiffTest
67
67
  super
68
68
  else
69
69
  # 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
70
+ capture_exceptions do
71
+ skip("Impacted files have not changed. Skipping...")
74
72
  end
73
+ self.time = execution.previous_runtime_s
75
74
  ::Minitest::Result.from(self)
76
75
  end
77
76
  ensure
@@ -45,7 +45,7 @@ module DiffTest
45
45
  end
46
46
 
47
47
  def self.insert_at_first_non_comment_line_str(content, text_to_insert)
48
- lines = content.lines.map(&:chomp)
48
+ lines = content.lines
49
49
 
50
50
  in_multiline_comment = false
51
51
  comment_type = nil
@@ -97,7 +97,7 @@ module DiffTest
97
97
  new_lines = lines.dup
98
98
  new_lines.insert(insert_index, text_to_insert)
99
99
 
100
- new_lines.join("\n")
100
+ new_lines.join
101
101
  end
102
102
  end
103
103
  end
@@ -8,21 +8,24 @@ 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
17
18
  has_previous_execution_with_no_impacted_changes = previous_test_executions.any? do |previous_test_execution|
18
19
  hashes_match = previous_test_execution['test_execution_impacted_files'].all? do |test_execution_impacted_file|
19
20
  impacted_file_id = test_execution_impacted_file['impacted_file_id'].to_s
20
- file_hash = test_execution_impacted_file['file_hash']
21
+ file_hash = test_execution_impacted_file['file_hash'].to_s
21
22
  impacted_file_path = @impacted_file_path_by_id[impacted_file_id]
22
23
 
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.12"
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.12
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-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty