fn: cancellations in WaitAsyncResource (#694)

* fn: cancellations in WaitAsyncResource

Added go context with cancel to wait async resource. Although
today, the only case for cancellation is shutdown, this cleans
up agent shutdown a little bit.

* fn: locked broadcast to avoid missed wake-ups

* fn: removed ctx arg to WaitAsyncResource and startDequeuer

This is confusing and unnecessary.
This commit is contained in:
Tolga Ceylan
2018-01-17 16:08:54 -08:00
committed by GitHub
parent 7c74c2fe88
commit 5a7778a656
6 changed files with 41 additions and 24 deletions

View File

@@ -116,10 +116,11 @@ func TestResourceAsyncWait(t *testing.T) {
// should block & wait
vals.mau = vals.mam
setTrackerTestVals(tr, &vals)
ch := tr.WaitAsyncResource()
ch1, cancel1 := tr.WaitAsyncResource()
defer cancel1()
select {
case <-ch:
case <-ch1:
t.Fatal("high water mark MEM over, should not trigger")
case <-time.After(time.Duration(500) * time.Millisecond):
}
@@ -129,20 +130,21 @@ func TestResourceAsyncWait(t *testing.T) {
setTrackerTestVals(tr, &vals)
select {
case <-ch:
case <-ch1:
case <-time.After(time.Duration(500) * time.Millisecond):
t.Fatal("high water mark MEM not over, should trigger")
}
// get a new channel to prevent previous test interference
ch = tr.WaitAsyncResource()
ch2, cancel2 := tr.WaitAsyncResource()
defer cancel2()
// should block & wait
vals.cau = vals.cam
setTrackerTestVals(tr, &vals)
select {
case <-ch:
case <-ch2:
t.Fatal("high water mark CPU over, should not trigger")
case <-time.After(time.Duration(500) * time.Millisecond):
}
@@ -152,11 +154,10 @@ func TestResourceAsyncWait(t *testing.T) {
setTrackerTestVals(tr, &vals)
select {
case <-ch:
case <-ch2:
case <-time.After(time.Duration(500) * time.Millisecond):
t.Fatal("high water mark CPU not over, should trigger")
}
}
func TestResourceGetSimple(t *testing.T) {