selective-ruby-core 0.3.4-aarch64-linux → 0.4.0-aarch64-linux

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: 8b41bacdb4ae127eab160aba1c2b1ddf9a0bea1851b27a6b4022d86e8ad33927
4
- data.tar.gz: bd70701f3b1b563c9395aa9e1b4d501febf58cd5733881bd88bb53a94107fef1
3
+ metadata.gz: 19dcca12284632dc174387c6c9f91b1aab3b3c126c3f619056ad6c58ded57355
4
+ data.tar.gz: 5c3bf061c72bb6e7c58d66bde97948101407845745a4b985a1dad170f0d258eb
5
5
  SHA512:
6
- metadata.gz: f92b4786b286da17b71202c18a30a452287af86c318623fb3798256db223c1d700398eb41db9b7f1d483c1016aa708dc4ab457eb4d4f6a0adc1dc00ea8f6c9bd
7
- data.tar.gz: be67645640dd7ca06976b77cdf7ea27a5ae7cbdb475228ed216f3541be9b85509c4ae172222166bae0856f77f3d5cb8e17b77cac992a21d372b35316c2780ca3
6
+ metadata.gz: 3aed9fda68583317c63b108071aee07bb37920f227270a7913aa13c02fea22121d5c3561dd3928deb68616181a9f0d6806b2505066a0e3f62951988697b1e455
7
+ data.tar.gz: 2c3a80a10c175f5ad20db3aeb8e9cef1add3b13d22a548e2debc9c2d5e9ad9ea61d4b20d923b04998e973d4cc689111a5eb1138c62474b45228a047c5dec85c5
@@ -29,7 +29,9 @@ module Selective
29
29
  def initialize(runner_class, runner_args, debug: false, log: false)
30
30
  @debug = debug
31
31
  @log = log
32
+ @timings = Timings.new
32
33
  @runner = runner_class.new(runner_args, method(:test_case_callback))
34
+ @timings.mark("runner_ready")
33
35
  @retries = 0
34
36
  @pending_commands = []
35
37
  end
@@ -75,12 +77,11 @@ module Selective
75
77
 
76
78
  private
77
79
 
78
- attr_reader :runner, :pipe, :transport_pid, :retries, :diff
80
+ attr_reader :runner, :pipe, :transport_pid, :retries, :timings
79
81
 
80
82
  # Resolved on first use rather than in the constructor: `selective
81
- # exec` (the plain framework run behind the manifest dry-run) never
82
- # connects, so it must not require the CI environment that naming a
83
- # runner validates.
83
+ # exec` (a plain framework run) never connects, so it must not require
84
+ # the CI environment that naming a runner validates.
84
85
  def runner_id
85
86
  @runner_id ||= safe_filename(get_runner_id)
86
87
  end
@@ -117,7 +118,10 @@ module Selective
117
118
  def next_command
118
119
  return @pending_commands.shift if @pending_commands.any?
119
120
 
120
- JSON.parse(pipe.read, symbolize_names: true)
121
+ started = Timings.monotonic_ms
122
+ message = pipe.read
123
+ timings.waited(Timings.monotonic_ms - started)
124
+ JSON.parse(message, symbolize_names: true)
121
125
  end
122
126
 
123
127
  # One connection: true when the run finished on it, false when it was
@@ -296,6 +300,7 @@ module Selective
296
300
  message = pipe.read
297
301
  response = JSON.parse(message, symbolize_names: true)
298
302
  if response[:command] == "connected"
303
+ timings.mark("connected")
299
304
  @connectivity = true
300
305
  break
301
306
  end
@@ -370,17 +375,19 @@ module Selective
370
375
  end
371
376
 
372
377
  def handle_test_manifest(_data)
378
+ timings.mark("manifest_requested")
373
379
  self.class.restore_reporting!
374
380
  logger.info("Sending Response: test_manifest")
375
- data = {test_cases: runner.manifest["examples"] || runner.manifest["test_cases"]}
376
- if TestMap.tree_requested? && (tree = test_map_tree)
381
+ manifest = timings.measure("manifest_list") { runner.manifest }
382
+ data = {test_cases: manifest["examples"] || manifest["test_cases"]}
383
+ if TestMap.tree_requested? && (tree = timings.measure("manifest_tree") { test_map_tree })
377
384
  data[:test_map_tree] = tree
378
385
  end
379
- num_commits = build_env["num_commits"] || 1000
380
- if (diff = get_diff(num_commits))
386
+ if (diff = timings.measure("manifest_diff") { get_diff })
381
387
  data[:modified_test_files] = modified_test_files(diff)
382
- data[:correlated_files] = correlated_files(diff, num_commits)
383
388
  end
389
+ timings.mark("manifest_sent")
390
+ data[:timings] = timings.startup
384
391
  write({type: "test_manifest", data: data})
385
392
  end
386
393
 
@@ -401,7 +408,7 @@ module Selective
401
408
  end
402
409
 
403
410
  def handle_run_test_cases(data)
404
- runner.run_test_cases(data[:test_case_ids])
411
+ timings.batch { runner.run_test_cases(data[:test_case_ids]) }
405
412
  end
406
413
 
407
414
  # Todo: Rename this command to match the method name
@@ -421,6 +428,7 @@ module Selective
421
428
 
422
429
  with_error_handling do
423
430
  Selective::Ruby::Core::Controller.report_at_finish[:connection_retries] = @retries
431
+ Selective::Ruby::Core::Controller.report_at_finish[:timings] = timings.finish
424
432
  write({type: "report_at_finish", data: Selective::Ruby::Core::Controller.report_at_finish})
425
433
 
426
434
  runner.finish unless exit_status.is_a?(Integer)
@@ -464,13 +472,12 @@ module Selective
464
472
  logger.warn("Test map upload failed: #{e.class}: #{e.message}")
465
473
  end
466
474
 
467
- def correlated_files(diff, num_commits)
468
- Selective::Ruby::Core::FileCorrelator.new(diff, num_commits, build_env["target_branch"]).correlate
469
- end
470
-
471
475
  def test_case_callback(test_case)
472
476
  logger.info("Sending Response: test_case_result: #{test_case[:id]}")
477
+ timings.example(test_case[:run_time])
478
+ started = Timings.monotonic_ms
473
479
  write({type: "test_case_result", data: test_case})
480
+ timings.wrote(Timings.monotonic_ms - started)
474
481
  end
475
482
 
476
483
  def modified_test_files(diff)
@@ -479,11 +486,15 @@ module Selective
479
486
  end
480
487
  end
481
488
 
482
- def get_diff(num_commits)
489
+ # Two-dot diff against the target's tip: comparing trees needs no
490
+ # history, so one commit is enough. A full clone is fetched without a
491
+ # depth, which would otherwise make it shallow.
492
+ def get_diff
483
493
  target_branch = build_env["target_branch"]
484
494
  return if target_branch.nil? || target_branch.empty?
485
495
 
486
- Open3.capture2e("git fetch origin #{target_branch} --depth=#{num_commits}").then do |output, status|
496
+ depth = shallow_repository? ? " --depth=1" : ""
497
+ Open3.capture2e("git fetch origin #{target_branch}#{depth}").then do |output, status|
487
498
  unless status.success?
488
499
  print_warning "Selective was unable to fetch the target branch. This may result in a sub-optimal test order. If the issue persists, please contact support. The output was:\n\n#{output}"
489
500
  return
@@ -500,6 +511,11 @@ module Selective
500
511
  end
501
512
  end
502
513
 
514
+ def shallow_repository?
515
+ output, status = Open3.capture2e("git rev-parse --is-shallow-repository")
516
+ status.success? && output.strip == "true"
517
+ end
518
+
503
519
  def debug?
504
520
  @debug
505
521
  end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Selective
4
+ module Ruby
5
+ module Core
6
+ # Where a runner's time goes, from clock reads at points the controller
7
+ # already passes. Startup marks go out with the manifest; batch totals
8
+ # go out with report_at_finish. All in milliseconds; `*_at` marks are
9
+ # Unix epoch, so the server can line them up with its own.
10
+ class Timings
11
+ attr_reader :marks
12
+
13
+ def initialize(loaded_at_ms: LOADED_AT_MS)
14
+ @marks = {"core_loaded_at" => loaded_at_ms}
15
+ started = self.class.process_started_at_ms
16
+ @marks["process_started_at"] = started if started
17
+ @batches = 0
18
+ @run_ms = 0
19
+ @idle_ms = 0
20
+ @write_ms = 0
21
+ @example_ms = 0.0
22
+ @examples = 0
23
+ end
24
+
25
+ def self.now_ms
26
+ Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
27
+ end
28
+
29
+ def self.monotonic_ms
30
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
31
+ end
32
+
33
+ # Linux only: the process's start from /proc, so time spent before
34
+ # this gem loaded (bundler, the app's own requires) is visible.
35
+ def self.process_started_at_ms
36
+ ticks = File.read("/proc/self/stat").split(") ").last.split(" ")[19].to_i
37
+ uptime_s = File.read("/proc/uptime").split(" ").first.to_f
38
+ hertz = 100.0
39
+ now_ms - ((uptime_s - ticks / hertz) * 1000).round
40
+ rescue SystemCallError, NoMethodError
41
+ nil
42
+ end
43
+
44
+ def mark(name)
45
+ @marks["#{name}_at"] ||= self.class.now_ms
46
+ end
47
+
48
+ def measure(name)
49
+ started = self.class.monotonic_ms
50
+ yield
51
+ ensure
52
+ @marks["#{name}_ms"] = self.class.monotonic_ms - started
53
+ end
54
+
55
+ # Time spent blocked on the next command, split at the first batch:
56
+ # before it is startup, after it is waiting for work.
57
+ def waited(ms)
58
+ if @batches.zero?
59
+ @marks["wait_before_first_batch_ms"] = (@marks["wait_before_first_batch_ms"] || 0) + ms
60
+ else
61
+ @idle_ms += ms
62
+ end
63
+ end
64
+
65
+ def batch
66
+ mark("first_batch")
67
+ started = self.class.monotonic_ms
68
+ yield
69
+ ensure
70
+ @batches += 1
71
+ @run_ms += self.class.monotonic_ms - started
72
+ mark_last_batch
73
+ end
74
+
75
+ def wrote(ms)
76
+ @write_ms += ms
77
+ end
78
+
79
+ def example(run_time_s)
80
+ @examples += 1
81
+ @example_ms += run_time_s.to_f * 1000
82
+ end
83
+
84
+ def startup
85
+ marks.dup
86
+ end
87
+
88
+ def finish
89
+ {
90
+ "batches" => @batches,
91
+ "examples" => @examples,
92
+ "run_ms" => @run_ms,
93
+ "example_ms" => @example_ms.round,
94
+ "outside_examples_ms" => [@run_ms - @example_ms.round, 0].max,
95
+ "idle_between_batches_ms" => @idle_ms,
96
+ "result_write_ms" => @write_ms
97
+ }.merge(marks.slice("first_batch_at", "last_batch_at", "wait_before_first_batch_ms"))
98
+ end
99
+
100
+ private
101
+
102
+ def mark_last_batch
103
+ @marks["last_batch_at"] = self.class.now_ms
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.3.4"
6
+ VERSION = "0.4.0"
7
7
  end
8
8
  end
9
9
  end
@@ -13,6 +13,8 @@ loader.setup
13
13
  module Selective
14
14
  module Ruby
15
15
  module Core
16
+ LOADED_AT_MS = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
17
+
16
18
  class Error < StandardError; end
17
19
  class ConnectionLostError < StandardError; end
18
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selective-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Benjamin Wood
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2026-11-19 00:00:00.000000000 Z
12
+ date: 2026-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logger
@@ -64,11 +64,9 @@ files:
64
64
  - ext/selective_tracer/extconf.rb
65
65
  - ext/selective_tracer/selective_tracer.c
66
66
  - lib/bin/build_env.sh
67
- - lib/bin/file_correlation_collector.sh
68
67
  - lib/bin/transport
69
68
  - lib/selective-ruby-core.rb
70
69
  - lib/selective/ruby/core/controller.rb
71
- - lib/selective/ruby/core/file_correlator.rb
72
70
  - lib/selective/ruby/core/helper.rb
73
71
  - lib/selective/ruby/core/stdio_transport.rb
74
72
  - lib/selective/ruby/core/test_map.rb
@@ -76,6 +74,7 @@ files:
76
74
  - lib/selective/ruby/core/test_map/tracer.rb
77
75
  - lib/selective/ruby/core/test_map/tree.rb
78
76
  - lib/selective/ruby/core/test_map/uploader.rb
77
+ - lib/selective/ruby/core/timings.rb
79
78
  - lib/selective/ruby/core/version.rb
80
79
  homepage: https://www.selective.ci
81
80
  licenses:
@@ -1,141 +0,0 @@
1
- #!/bin/bash
2
-
3
- # The first argument is the number of commits to process
4
- branch=$1
5
- num_commits=$2
6
-
7
- # Initialize an associative array to hold the files to check
8
- declare -A files_to_check
9
-
10
- # Populate the array with the script arguments, starting from the second argument
11
- for file in "${@:3}"
12
- do
13
- files_to_check["$file"]=1
14
- done
15
-
16
- # Get a list of all commit hashes, in reverse order
17
- all_commits=$(git log origin/$branch --no-merges --format=%H --reverse -n $num_commits)
18
-
19
- # Initialize an associative array to store the test files
20
- declare -A test_files
21
- declare -A uncorrelated_test_files
22
-
23
- # Initialize an array to store the files changed in the previous commit
24
- prev_changed_files=()
25
-
26
- # For each commit...
27
- for commit in $all_commits
28
- do
29
- # Get a list of all files that were changed in the current commit
30
- files=$(git diff-tree --no-commit-id --name-only -r $commit)
31
-
32
- declare -A correlated_test_files
33
-
34
- # # For each file in the list of files changed in the previous commit...
35
- for file in "${prev_changed_files[@]}"
36
- do
37
- # If the file is in the list of files to check...
38
- if [[ ${files_to_check[$file]} ]]; then
39
- # For each file...
40
- for test_file in $files
41
- do
42
- # If the file is in the test/ directory and ends with _test.rb...
43
- if [[ $test_file == spec/*_spec.rb ]]
44
- then
45
- # Increment the count in the associative array
46
- test_files["$file|$test_file"]=$((test_files["$file|$test_file"]+1))
47
- # Add the test file to the correlated_test_files array
48
- correlated_test_files["$test_file"]=1
49
- fi
50
- done
51
- fi
52
- done
53
-
54
- # For each file in the list of files changed in the current commit...
55
- for file in $files
56
- do
57
- # If the file is in the list of files to check...
58
- if [[ ${files_to_check[$file]} ]]; then
59
- # For each file...
60
- for test_file in $files
61
- do
62
- # If the file is in the test/ directory and ends with _test.rb...
63
- if [[ $test_file == spec/*_spec.rb ]]
64
- then
65
- # Increment the count in the associative array
66
- test_files["$file|$test_file"]=$((test_files["$file|$test_file"]+1))
67
- # Add the test file to the correlated_test_files array
68
- correlated_test_files["$test_file"]=1
69
- fi
70
- done
71
- fi
72
- done
73
-
74
- # For each file...
75
- for test_file in $files
76
- do
77
- # If the file is in the test/ directory and ends with _test.rb...
78
- if [[ $test_file == spec/*_spec.rb ]]
79
- then
80
- # If the test file is not correlated to any of the files to check in the current commit...
81
- if [[ -z ${correlated_test_files[$test_file]} ]]
82
- then
83
- # Increment the count in the associative array
84
- uncorrelated_test_files["$test_file"]=$((uncorrelated_test_files["$test_file"]+1))
85
- fi
86
- fi
87
- done
88
-
89
- # Clear the correlated_test_files array for the next commit
90
- unset correlated_test_files
91
-
92
- # Store the list of files changed in this commit for the next iteration
93
- prev_changed_files=($files)
94
- done
95
-
96
- # OUTPUT
97
-
98
- # Initialize an associative array to hold the JSON strings for each file
99
- declare -A file_jsons
100
-
101
- # Add the test_files to the file_jsons associative array
102
- for key in "${!test_files[@]}"
103
- do
104
- file=${key%|*}
105
- test_file=${key#*|}
106
- count=${test_files[$key]}
107
- # Append to the JSON string for this file
108
- file_jsons["$file"]+="\"$test_file\": $count,"
109
- done
110
-
111
- # Initialize an empty string for the test_files JSON
112
- correlated_files_json=""
113
-
114
- # Add the file_jsons to the correlated_files_json string
115
- for file in "${!file_jsons[@]}"
116
- do
117
- # Remove the trailing comma from the JSON string for this file
118
- file_json=${file_jsons[$file]%?}
119
- # Append to the correlated_files_json string
120
- correlated_files_json+="\"$file\": { $file_json },"
121
- done
122
-
123
- # Remove the trailing comma from the correlated_files_json string
124
- correlated_files_json=${correlated_files_json%?}
125
-
126
- # Initialize an empty string for the uncorrelated_test_files JSON
127
- uncorrelated_files_json=""
128
-
129
- # Add the uncorrelated_test_files to the uncorrelated_files_json string
130
- for key in "${!uncorrelated_test_files[@]}"
131
- do
132
- count=${uncorrelated_test_files[$key]}
133
- # Append to the uncorrelated_files_json string
134
- uncorrelated_files_json+="\"$key\": $count,"
135
- done
136
-
137
- # Remove the trailing comma from the uncorrelated_files_json string
138
- uncorrelated_files_json=${uncorrelated_files_json%?}
139
-
140
- # Output the JSON
141
- echo "{ \"correlated_files\": { $correlated_files_json }, \"uncorrelated_files\": { $uncorrelated_files_json } }"
@@ -1,41 +0,0 @@
1
- module Selective
2
- module Ruby
3
- module Core
4
- class FileCorrelator
5
- include Helper
6
-
7
- class FileCorrelatorError < StandardError; end
8
-
9
- FILE_CORRELATION_COLLECTOR_PATH = File.join(ROOT_GEM_PATH, "lib", "bin", "file_correlation_collector.sh")
10
-
11
- def initialize(diff, num_commits, target_branch)
12
- @diff = diff.reject {|f| f =~ /^spec\// }
13
- @num_commits = num_commits
14
- @target_branch = target_branch
15
- end
16
-
17
- def correlate
18
- JSON.parse(get_correlated_files, symbolize_names: true)
19
- rescue FileCorrelatorError, JSON::ParserError
20
- print_warning(<<~MSG)
21
- Selective was unable to correlate the diff to test files. This may result in a sub-optimal test order.
22
- If the issue persists, please contact support.
23
- MSG
24
- end
25
-
26
- private
27
-
28
- attr_reader :diff, :num_commits, :target_branch
29
-
30
- def get_correlated_files
31
- Open3.capture2e("#{FILE_CORRELATION_COLLECTOR_PATH} #{target_branch} #{num_commits} #{diff.join(" ")}").then do |output, status|
32
-
33
- raise FileCorrelatorError unless status.success?
34
-
35
- output
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end