Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Rouge <jer329@cornell.edu>
  • Loading branch information
wk8 committed Oct 6, 2018
1 parent 88d7613 commit b5ed82e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions manager/deallocator/deallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (deallocator *Deallocator) Run(ctx context.Context) error {
// and TODO wkpo where is this used???
func (deallocator *Deallocator) Stop() {
close(deallocator.stopChan)
<-deallocator.doneChan
}

func (deallocator *Deallocator) processPendingDeleteService(ctx context.Context, service *api.Service) error {
Expand Down
25 changes: 18 additions & 7 deletions manager/deallocator/deallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,37 @@ func TestDeallocatorInit(t *testing.T) {
// create and start the deallocator
deallocator := New(s)

completed := make(chan struct{})
ran := make(chan struct{})
var returnValue error
go func() {
returnValue = deallocator.Run(context.Background())
// allows checking that `Run` does return after we've stopped
close(completed)
close(ran)
}()

// and then stop it immediately - we're just interested in the init
// phase for this test
deallocator.Stop()
// phase for this test -
stopped := make(chan struct{})
go func() {
deallocator.Stop()
close(stopped)
}()

// let's wait for it to stop - shouldn't take too long
timeout := time.NewTimer(5 * time.Second) // TODO wkpo
// it shouldn't take too long to stop
timeout := time.NewTimer(1 * time.Second)
select {
case <-completed:
case <-stopped:
timeout.Stop()
case <-timeout.C:
t.Error("Waited for too long for the deallocator to stop, error from run")
}

// `Run` should have returned, too
select {
case <-ran:
default:
t.Error("Run hasn't returned")
}
require.NoError(t, returnValue)

// now let's check that the DB is in the state we expect
Expand Down

0 comments on commit b5ed82e

Please sign in to comment.