diff options
| author | Shulhan <ms@kilabit.info> | 2023-05-27 00:38:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-05-30 23:34:53 +0700 |
| commit | ce7629725df373ece542141533f7ea27abfdb1e4 (patch) | |
| tree | 2b7109933e5ba4646432861afd1900eb6b25ad14 | |
| parent | ffd135e1089c277e2b140d233a691d063e0fca38 (diff) | |
| download | pakakeh.go-ce7629725df373ece542141533f7ea27abfdb1e4.tar.xz | |
lib/smtp: use WaitAlive instead of time.Sleep
This cut the test time to 0.100 second, match with sleep duration.
| -rw-r--r-- | lib/smtp/smtp_test.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/smtp/smtp_test.go b/lib/smtp/smtp_test.go index f7b18f4c..5cd48d30 100644 --- a/lib/smtp/smtp_test.go +++ b/lib/smtp/smtp_test.go @@ -12,6 +12,7 @@ import ( libcrypto "github.com/shuLhan/share/lib/crypto" "github.com/shuLhan/share/lib/email/dkim" + libnet "github.com/shuLhan/share/lib/net" "github.com/shuLhan/share/lib/test" ) @@ -107,16 +108,19 @@ func testNewClient(withAuth bool) (cl *Client) { } func TestMain(m *testing.M) { - var ( - s int - ) - testRunServer() - time.Sleep(100 * time.Millisecond) + // Wait for server to be alive. + var ( + timeout = 5 * time.Second + err error + ) + err = libnet.WaitAlive(`tcp`, testAddress, timeout) + if err != nil { + log.Fatal(err) + } - s = m.Run() - os.Exit(s) + os.Exit(m.Run()) } func TestParsePath(t *testing.T) { |
