Skip to content

Commit

Permalink
Merge pull request coreos#1651 from endocode/dongsu/unit-publisher-wa…
Browse files Browse the repository at this point in the history
…it-each

agent: make TestUnitStatePublisher wait for each goroutine to finish
  • Loading branch information
Dongsu Park authored Jul 27, 2016
2 parents d15413e + 8a8d690 commit 063e74f
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions agent/unit_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,36 @@ func TestUnitStatePublisherRunWithDelays(t *testing.T) {
)
}

waitUnitToPublish := func(uName string) {
select {
case name := <-usp.toPublish:
if name != uName {
t.Errorf("unexpected name on toPublish channel: %v", name)
}
case <-time.After(time.Second):
t.Fatal("did not receive on toPublish channel as expected")
}
}

// now queue some more unit states for publishing - expect them to hang
go usp.queueForPublish("foo.service", &unit.UnitState{UnitName: "foo.service", ActiveState: "active"})
go usp.queueForPublish("foo.service", &unit.UnitState{
UnitName: "foo.service",
ActiveState: "active",
})
waitUnitToPublish("foo.service")

go usp.queueForPublish("bar.service", &unit.UnitState{})
waitUnitToPublish("bar.service")

go usp.queueForPublish("baz.service", &unit.UnitState{})
waitUnitToPublish("baz.service")

// re-queue one of the states; this should replace the above
go usp.queueForPublish("foo.service", &unit.UnitState{UnitName: "foo.service", ActiveState: "inactive"})
go usp.queueForPublish("foo.service", &unit.UnitState{
UnitName: "foo.service",
ActiveState: "inactive",
})
waitUnitToPublish("foo.service")

// wait for all publish workers to start
wgs.Wait()
Expand Down

0 comments on commit 063e74f

Please sign in to comment.