async_experiments 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -11
- data/lib/async_experiments.rb +25 -14
- data/lib/async_experiments/candidate_worker.rb +3 -3
- data/lib/async_experiments/experiment_control.rb +7 -3
- data/lib/async_experiments/experiment_error_worker.rb +7 -2
- data/lib/async_experiments/experiment_result.rb +19 -16
- data/lib/async_experiments/experiment_result_candidate_worker.rb +24 -0
- data/lib/async_experiments/experiment_result_control_worker.rb +29 -0
- data/lib/async_experiments/version.rb +1 -1
- data/spec/async_experiments_spec.rb +81 -20
- data/spec/candidate_worker_spec.rb +21 -24
- data/spec/examples.txt +48 -37
- data/spec/experiment_control_spec.rb +8 -6
- data/spec/experiment_error_worker_spec.rb +27 -6
- data/spec/experiment_result_candidate_worker_spec.rb +50 -0
- data/spec/experiment_result_control_worker_spec.rb +96 -0
- data/spec/experiment_result_spec.rb +103 -85
- metadata +8 -5
- data/lib/async_experiments/experiment_result_worker.rb +0 -36
- data/spec/experiment_result_worker_spec.rb +0 -106
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_experiments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Crosby-McCullough
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashdiff
|
@@ -136,7 +136,8 @@ files:
|
|
136
136
|
- lib/async_experiments/experiment_control.rb
|
137
137
|
- lib/async_experiments/experiment_error_worker.rb
|
138
138
|
- lib/async_experiments/experiment_result.rb
|
139
|
-
- lib/async_experiments/
|
139
|
+
- lib/async_experiments/experiment_result_candidate_worker.rb
|
140
|
+
- lib/async_experiments/experiment_result_control_worker.rb
|
140
141
|
- lib/async_experiments/util.rb
|
141
142
|
- lib/async_experiments/version.rb
|
142
143
|
- spec/async_experiments_spec.rb
|
@@ -144,8 +145,9 @@ files:
|
|
144
145
|
- spec/examples.txt
|
145
146
|
- spec/experiment_control_spec.rb
|
146
147
|
- spec/experiment_error_worker_spec.rb
|
148
|
+
- spec/experiment_result_candidate_worker_spec.rb
|
149
|
+
- spec/experiment_result_control_worker_spec.rb
|
147
150
|
- spec/experiment_result_spec.rb
|
148
|
-
- spec/experiment_result_worker_spec.rb
|
149
151
|
- spec/spec_helper.rb
|
150
152
|
- spec/util_spec.rb
|
151
153
|
homepage: http://github.com/alphagov/async_experiments
|
@@ -174,9 +176,10 @@ specification_version: 4
|
|
174
176
|
summary: An asynchronous experiment framework.
|
175
177
|
test_files:
|
176
178
|
- spec/experiment_result_spec.rb
|
179
|
+
- spec/experiment_result_candidate_worker_spec.rb
|
177
180
|
- spec/spec_helper.rb
|
181
|
+
- spec/experiment_result_control_worker_spec.rb
|
178
182
|
- spec/experiment_error_worker_spec.rb
|
179
|
-
- spec/experiment_result_worker_spec.rb
|
180
183
|
- spec/async_experiments_spec.rb
|
181
184
|
- spec/util_spec.rb
|
182
185
|
- spec/experiment_control_spec.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "async_experiments/experiment_result"
|
2
|
-
|
3
|
-
module AsyncExperiments
|
4
|
-
class ExperimentResultWorker
|
5
|
-
include Sidekiq::Worker
|
6
|
-
|
7
|
-
sidekiq_options queue: :experiments
|
8
|
-
|
9
|
-
LOCK_TIMEOUT = 60
|
10
|
-
|
11
|
-
def perform(name, id, run_output, duration, type)
|
12
|
-
type = type.to_sym
|
13
|
-
|
14
|
-
Sidekiq.redis do |redis|
|
15
|
-
this_branch = ExperimentResult.new(name, id, type, redis, statsd, run_output, duration)
|
16
|
-
|
17
|
-
if this_branch.control?
|
18
|
-
candidate = ExperimentResult.new(name, id, :candidate, redis, statsd)
|
19
|
-
if candidate.available?
|
20
|
-
this_branch.process_run_output(candidate)
|
21
|
-
else
|
22
|
-
self.class.perform_in(5, name, id, run_output, duration, type)
|
23
|
-
end
|
24
|
-
elsif this_branch.candidate?
|
25
|
-
this_branch.store_run_output
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def statsd
|
33
|
-
AsyncExperiments.statsd
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "async_experiments"
|
3
|
-
require "async_experiments/experiment_result"
|
4
|
-
require "async_experiments/experiment_result_worker"
|
5
|
-
|
6
|
-
RSpec.describe AsyncExperiments::ExperimentResultWorker do
|
7
|
-
let(:name) { "some_experiment" }
|
8
|
-
let(:id) { SecureRandom.uuid }
|
9
|
-
|
10
|
-
let(:statsd) { double(:statsd) }
|
11
|
-
let(:redis) { double(:redis) }
|
12
|
-
let(:redis_key) { double(:redis_key) }
|
13
|
-
|
14
|
-
let(:control_output) { "control output" }
|
15
|
-
let(:control_duration) { 10.0 }
|
16
|
-
|
17
|
-
let(:candidate_output) { "candidate output" }
|
18
|
-
let(:candidate_duration) { 5.0 }
|
19
|
-
|
20
|
-
let(:control) {
|
21
|
-
double(:control,
|
22
|
-
control?: true,
|
23
|
-
candidate?: false,
|
24
|
-
key: redis_key,
|
25
|
-
)
|
26
|
-
}
|
27
|
-
let(:candidate) {
|
28
|
-
double(:candidate,
|
29
|
-
candidate?: true,
|
30
|
-
control?: false,
|
31
|
-
key: redis_key,
|
32
|
-
)
|
33
|
-
}
|
34
|
-
|
35
|
-
subject { described_class.new }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow(Sidekiq).to receive(:redis).and_yield(redis)
|
39
|
-
AsyncExperiments.statsd = statsd
|
40
|
-
end
|
41
|
-
|
42
|
-
it "uses the 'experiments' queue" do
|
43
|
-
Sidekiq::Testing.fake! do
|
44
|
-
described_class.perform_async
|
45
|
-
|
46
|
-
expect(described_class.jobs.size).to eq(1)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "if we're the candidate" do
|
51
|
-
let(:type) { "candidate" }
|
52
|
-
|
53
|
-
it "stores the run output and duration" do
|
54
|
-
expect(AsyncExperiments::ExperimentResult).to receive(:new)
|
55
|
-
.with(name, id, type.to_sym, redis, statsd, candidate_output, candidate_duration)
|
56
|
-
.and_return(candidate)
|
57
|
-
|
58
|
-
expect(candidate).to receive(:store_run_output)
|
59
|
-
|
60
|
-
subject.perform(name, id, candidate_output, candidate_duration, type)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "if we're the control" do
|
65
|
-
let(:type) { "control" }
|
66
|
-
|
67
|
-
before do
|
68
|
-
expect(AsyncExperiments::ExperimentResult).to receive(:new)
|
69
|
-
.with(name, id, :control, redis, statsd, control_output, control_duration)
|
70
|
-
.and_return(control)
|
71
|
-
|
72
|
-
expect(AsyncExperiments::ExperimentResult).to receive(:new)
|
73
|
-
.with(name, id, :candidate, redis, statsd)
|
74
|
-
.and_return(candidate)
|
75
|
-
end
|
76
|
-
|
77
|
-
context "and the candidate is available" do
|
78
|
-
before do
|
79
|
-
allow(candidate).to receive(:available?).and_return(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "processes the run output with the candidate" do
|
83
|
-
expect(control).to receive(:process_run_output).with(candidate)
|
84
|
-
subject.perform(name, id, control_output, control_duration, type)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "but the candidate is unavailable" do
|
89
|
-
before do
|
90
|
-
allow(candidate).to receive(:available?).and_return(false)
|
91
|
-
allow(described_class).to receive(:perform_in)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "does not process the run output" do
|
95
|
-
expect(control).not_to receive(:process_run_output)
|
96
|
-
subject.perform(name, id, control_output, control_duration, type)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "schedules the job to run again later" do
|
100
|
-
args = [name, id, control_output, control_duration]
|
101
|
-
expect(described_class).to receive(:perform_in).with(5, *args, type.to_sym)
|
102
|
-
subject.perform(*args, type)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|