git » chasquid » commit 4357379

test: Implement retries on the load generator

author Alberto Bertogli
2020-03-28 16:28:37 UTC
committer Alberto Bertogli
2020-03-28 16:42:04 UTC
parent 35c2d1d485d86f4e7186e598535972b25eb61b7a

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 -0

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
 		}
 	}