Skip to content

Commit 2e72ea1

Browse files
committed
Remove threads
This will allow us to record and replay test execution to reproduce a failure deterministically.
1 parent bad6762 commit 2e72ea1

3 files changed

Lines changed: 7 additions & 42 deletions

File tree

‎lib/quickdraw/cli.rb‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ def parse_options
4444
self.watch = true
4545
end
4646

47-
parser.on("-t N", "--threads N", Integer, "Number of Threads per Process") do |it|
48-
self.threads = it
49-
end
50-
5147
parser.on("-s N", "--seed N", Integer, "Seed for randomization") do |it|
5248
self.seed = it
5349
end
@@ -78,10 +74,6 @@ def watch=(value)
7874
end
7975
end
8076

81-
def threads=(value)
82-
@threads = value
83-
end
84-
8577
def seed=(value)
8678
@seed = value
8779
end
@@ -131,7 +123,6 @@ def run_once
131123
$quickdraw_runner = Quickdraw::Runner.new(
132124
backtrace: @backtrace,
133125
processes: @processes || Quickdraw::Config.processes,
134-
threads: @threads || Quickdraw::Config.threads,
135126
files: Dir.glob(@files),
136127
seed: @seed || Random.new_seed,
137128
)

‎lib/quickdraw/configuration.rb‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
class Quickdraw::Configuration
44
DEFAULT_PROCESSES = Quickdraw::Platform.supports_forking? ? Quickdraw::Platform.non_blocking_cores : 1
5-
DEFAULT_THREADS = 2
65

76
def initialize
87
@failure_symbol = "\e[31m⨯\e[0m"
98
@success_symbol = "\e[32m∘\e[0m"
109
@processes = DEFAULT_PROCESSES
11-
@threads = DEFAULT_THREADS
1210
@success_emoji = %w[💃 🕺 🎉 🎊 💪 👏 🙌 ✨ 🥳 🎈 🌈 🎯 🏆]
1311
@before_forking_callbacks = []
1412
@after_forking_callbacks = []
@@ -18,7 +16,7 @@ def initialize
1816
attr_accessor :processes
1917
attr_accessor :success_emoji
2018
attr_accessor :success_symbol
21-
attr_accessor :threads
19+
2220
attr_reader :before_forking_callbacks
2321
attr_reader :after_forking_callbacks
2422

‎lib/quickdraw/runner.rb‎

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ module Message
1111
Stopping = "\x04"
1212
end
1313

14-
def initialize(backtrace: false, processes:, threads:, files:, seed:)
14+
def initialize(backtrace: false, processes:, files:, seed:)
1515
@backtrace = backtrace
1616
@processes = processes
17-
@threads = threads
1817
@seed = seed
1918
@random = Random.new(seed)
2019
@files = files.shuffle(random: @random)
@@ -38,7 +37,7 @@ def call
3837
fork_processes
3938
@cluster.wait
4039
else
41-
@tests.each do |test|
40+
@tests.each do |context, description, skip, block|
4241
context.new(description:, skip:, block:, runner: self).run
4342
end
4443
end
@@ -94,8 +93,6 @@ def load_tests
9493

9594
@tests.shuffle!(random: @random)
9695
@tests.freeze
97-
# Try to break up the tests into at least 20 batches per core.
98-
@batch = (@tests.size / @processes / 20).clamp(1, 500)
9996
end
10097

10198
def fork_processes
@@ -128,29 +125,13 @@ def error!(error)
128125
def work(socket)
129126
Quickdraw::Config.after_forking_callbacks.each(&:call)
130127

131-
batch = @batch
132-
queue = Thread::SizedQueue.new(batch)
133128
tests = @tests
134-
tests_size = @tests.size
135-
136-
threads = @threads.times.map do |i|
137-
Thread.new do
138-
while true
139-
index = queue.pop
140-
break if index == :stop
141-
context, description, skip, block = tests[index]
142-
context.new(description:, skip:, block:, runner: self).run
143-
end
144-
end
145-
end
146129

147130
while true
148131
socket.write Message::Fetch
149132

150133
case socket.read(1)
151134
when nil, Message::Stop
152-
threads.each { queue.push(:stop) }
153-
threads.each(&:join)
154135
socket.write Message::Stopping
155136
socket.write JSON.generate({
156137
errors: @errors.to_a,
@@ -159,13 +140,9 @@ def work(socket)
159140
})
160141
break
161142
when Message::Work
162-
cursor = socket.read(4).unpack1("L<")
163-
stop = [tests_size, cursor + batch].min
164-
165-
while cursor < stop
166-
queue.push(cursor)
167-
cursor += 1
168-
end
143+
index = socket.read(4).unpack1("L<")
144+
context, description, skip, block = tests[index]
145+
context.new(description:, skip:, block:, runner: self).run
169146
else
170147
raise "Unhandled message: #{message}"
171148
end
@@ -175,7 +152,6 @@ def work(socket)
175152
def supervise(worker)
176153
socket = worker.socket
177154
mutex = @mutex
178-
batch = @batch
179155
progress = 0
180156

181157
console = IO.console
@@ -198,7 +174,7 @@ def supervise(worker)
198174
if @cursor < tests_length
199175
socket.write Message::Work
200176
socket.write [@cursor].pack("L<")
201-
@cursor += batch
177+
@cursor += 1
202178
else
203179
socket.write Message::Stop
204180
end

0 commit comments

Comments
 (0)