From 43573797379b6e9364e46bc01554698bdecd040d Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 28 Mar 2020 16:28:37 +0000 Subject: [PATCH] test: Implement retries on the load generator If the load generator is sending emails too fast, chasquid queue might hit the maximum size and fail the test. This patch makes it sleep and retry, to give the server some time to catch up. Thanks to Max Mazurov (fox.cpp@disroot.org) for reporting this problem. --- test/util/loadgen.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/util/loadgen.go b/test/util/loadgen.go index ca5c0ec..4653442 100644 --- a/test/util/loadgen.go +++ b/test/util/loadgen.go @@ -7,6 +7,7 @@ import ( "flag" "net" "net/http" + "net/textproto" "runtime" "sync" "time" @@ -172,6 +173,7 @@ func one() error { return err } + retry: w, err := client.Data() if err != nil { return err @@ -182,6 +184,16 @@ func one() error { } err = w.Close() if err != nil { + // If we are sending too fast we might hit chasquid's queue size + // limit. In that case, wait and try again. + // We detect it with error code 451 which is used for this + // situation. + if terr, ok := err.(*textproto.Error); ok { + if terr.Code == 451 { + time.Sleep(10 * time.Millisecond) + goto retry + } + } return err } }