Bound each shutdown stage by the stop deadline (closes #100)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Shutdown passes its context to every stage: the streamer, the four handlers, the WHOIS fetcher, the database maintainer and the HTTP server each stop waiting when it ends. A handler then skips its last write and logs how many updates it did not write, and the HTTP server closes the connections still open. The database is checkpointed and closed last, and left open once the deadline has passed, since a write may still hold it. The stop hook gives Shutdown 8 seconds and fx 9, inside the 10 seconds upaas and docker stop allow, so a stop signal exits 0. Model: opus-5-5
This commit was merged in pull request #130.
This commit is contained in:
@@ -155,3 +155,51 @@ func TestFetchAndUpdateMarksAnASWithoutReferral(t *testing.T) {
|
||||
baseInterval)
|
||||
}
|
||||
}
|
||||
|
||||
// TestASNFetcherStopReturnsByItsDeadline starts a fetcher, has it look up an
|
||||
// AS whose WHOIS server does not answer until the test ends, and stops it with
|
||||
// a short deadline while that lookup is in progress. Stop must return all the
|
||||
// same instead of waiting for the lookup.
|
||||
func TestASNFetcherStopReturnsByItsDeadline(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const stopDeadline = 100 * time.Millisecond
|
||||
|
||||
lookupStarted := make(chan struct{})
|
||||
release := make(chan struct{})
|
||||
|
||||
f := NewASNFetcher(newMockStore(), logger.New().Logger)
|
||||
f.whoisClient.DialContext = func(
|
||||
context.Context, string, string,
|
||||
) (net.Conn, error) {
|
||||
close(lookupStarted)
|
||||
<-release
|
||||
|
||||
return nil, syscall.ECONNREFUSED
|
||||
}
|
||||
|
||||
f.Start(t.Context())
|
||||
f.QueueImmediate(testASNA)
|
||||
|
||||
select {
|
||||
case <-lookupStarted:
|
||||
case <-time.After(handleMessageTimeout):
|
||||
t.Fatal("the fetcher did not start the lookup")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(t.Context(), stopDeadline)
|
||||
defer cancel()
|
||||
|
||||
if !returnsInTime(func() { f.Stop(ctx) }) {
|
||||
t.Fatalf("Stop with a deadline of %s did not return while a lookup "+
|
||||
"was in progress", stopDeadline)
|
||||
}
|
||||
|
||||
close(release)
|
||||
|
||||
select {
|
||||
case <-f.done:
|
||||
case <-time.After(handleMessageTimeout):
|
||||
t.Fatal("the fetcher goroutine did not return after the lookup ended")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user