-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathworker_executor_spec.rb
More file actions
69 lines (60 loc) · 1.8 KB
/
Copy pathworker_executor_spec.rb
File metadata and controls
69 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
require "spec_helper"
require "tmpdir"
RSpec.describe Agent::WorkerExecutor do
let(:env_dir) { Dir.mktmpdir("recurgent-worker-env-") }
let(:executor) { described_class.new }
before do
File.write(File.join(env_dir, "Gemfile"), "source \"https://rubygems.org\"\n")
end
after do
executor.shutdown
FileUtils.rm_rf(env_dir)
end
it "executes a request and returns value plus context snapshot" do
executor.start(env_dir: env_dir)
response = executor.execute(
payload: {
method_name: "add",
code: "context[:count] = context.fetch(:count, 0) + 1; result = args[0] + kwargs[:extra]",
args: [2],
kwargs: { extra: 3 },
context_snapshot: {}
},
timeout_seconds: 5
)
expect(response["status"]).to eq("ok")
expect(response["value"]).to eq(5)
expect(response["context_snapshot"]).to include("count" => 1)
end
it "returns non_serializable_result when worker value cannot cross JSON boundary" do
executor.start(env_dir: env_dir)
response = executor.execute(
payload: {
method_name: "bad_value",
code: "result = Object.new",
args: [],
kwargs: {},
context_snapshot: {}
},
timeout_seconds: 5
)
expect(response["status"]).to eq("error")
expect(response["error_type"]).to eq("non_serializable_result")
end
it "raises WorkerTimeout when the worker does not respond in time" do
executor.start(env_dir: env_dir)
expect do
executor.execute(
payload: {
method_name: "slow",
code: "sleep 0.1; result = 1",
args: [],
kwargs: {},
context_snapshot: {}
},
timeout_seconds: 0.01
)
end.to raise_error(Agent::WorkerExecutor::WorkerTimeout)
end
end