Skip to content

Commit 3a91448

Browse files
committed
test: add tests and update existing
1 parent f200d13 commit 3a91448

1 file changed

Lines changed: 65 additions & 4 deletions

File tree

test/network_generation/test_dataflow_dynamics.rb

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ module NetworkGeneration
298298
policy_graph[[cmp.c_child, task]][%w[out in]])
299299
end
300300

301-
it "uses in-graph policies over the computed ones" do
301+
it "merges in-graph policies with the computed ones" do
302302
plan.add(task0 = @task_m.new)
303303
plan.add(task1 = @task_m.new)
304304

@@ -307,10 +307,13 @@ module NetworkGeneration
307307

308308
task0.out_port.connect_to(task1.in_port, type: :buffer, size: 42)
309309

310-
@dynamics.should_receive(:policy_for).never
310+
@dynamics
311+
.should_receive(:policy_for)
312+
.with(task0, "out", "in", task1, nil)
313+
.and_return(type: :buffer, size: 10, init: nil)
311314
policy_graph = @dynamics.compute_connection_policies
312315

313-
assert_equal({ type: :buffer, size: 42 },
316+
assert_equal({ type: :buffer, size: 42, init: nil },
314317
policy_graph[[task0, task1]][%w[out in]])
315318
end
316319

@@ -360,6 +363,64 @@ module NetworkGeneration
360363
add_agents(tasks[0, 2])
361364
flexmock(@dynamics).should_receive(:propagate).with(tasks[0, 2])
362365
end
366+
367+
it "handles the case where the explicit policy sets the type to :data" do
368+
plan.add(task0 = @task_m.new)
369+
plan.add(task1 = @task_m.new)
370+
371+
add_agents(tasks = [task0, task1])
372+
flexmock(@dynamics).should_receive(:propagate).with(tasks)
373+
374+
task0.out_port.connect_to task1.in_port, type: :data
375+
376+
flexmock(@dynamics)
377+
.should_receive(:policy_for)
378+
.with(task0, "out", "in", task1, nil)
379+
.and_return(type: :buffer, size: 10, init: true)
380+
381+
policy_graph = @dynamics.compute_connection_policies
382+
expected_policy = { type: :data, init: true }
383+
assert_equal(expected_policy,
384+
policy_graph[[task0, task1]][%w[out in]])
385+
end
386+
end
387+
388+
describe "merge_policy" do
389+
before do
390+
@dynamics = NetworkGeneration::DataFlowDynamics.new(plan)
391+
end
392+
393+
it "merges policies by preferring explicit values over " \
394+
"computed values" do
395+
explicit_policy = { type: :buffer, size: 20, init: true }
396+
computed_policy = { type: :buffer, size: 10, init: true }
397+
398+
merged_policy =
399+
@dynamics.merge_policy(explicit_policy, computed_policy)
400+
401+
assert_equal({ type: :buffer, size: 20, init: true }, merged_policy)
402+
end
403+
404+
it "removes the size value when the type is set to :data" do
405+
explicit_policy = { type: :data, init: true }
406+
computed_policy = { type: :buffer, size: 10, init: true }
407+
408+
merged_policy =
409+
@dynamics.merge_policy(explicit_policy, computed_policy)
410+
411+
assert_equal({ type: :data, init: true }, merged_policy)
412+
end
413+
414+
it "falls back to computed values when explicit values " \
415+
"are not provided" do
416+
explicit_policy = {}
417+
computed_policy = { type: :buffer, size: 10, init: true }
418+
419+
merged_policy =
420+
@dynamics.merge_policy(explicit_policy, computed_policy)
421+
422+
assert_equal({ type: :buffer, size: 10, init: true }, merged_policy)
423+
end
363424
end
364425

365426
describe "#policy_for" do
@@ -459,7 +520,7 @@ module NetworkGeneration
459520
flexmock(@source_t.out_port.model)
460521
.should_receive(:init_policy?).explicitly
461522
.and_return(true)
462-
523+
463524
@source_t.out_port.model.init_policy(true)
464525
policy = @dynamics.policy_for(@source_t, "out", "in", @sink_t, nil)
465526

0 commit comments

Comments
 (0)