mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user