-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_test.go
51 lines (41 loc) · 897 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"os"
"testing"
"time"
)
func init() {
trace = log.New(os.Stdout, "INFO: ", log.LstdFlags)
}
func TestDialTimeout(t *testing.T) {
host := "spacedecode.com"
addr := "foo@" + host
passed := false
// Timeouts: I'm not sue if this is too much time?
funcTimeout := time.Second
// If the timeout fails, we impose a slightly higher timeout
// to this test so it doesn't block forever.
testTimeout := time.Second * 2
// Setup the exit channel so we can block
exit := make(chan struct{})
// We run this in a goroutine so we can wait on the channel.
go func() {
go func() {
ticker := time.NewTicker(testTimeout)
for range ticker.C {
exit <- struct{}{}
}
}()
_, err := isDeliverable(host+":25", addr, funcTimeout)
if err == errTimeout {
exit <- struct{}{}
passed = true
return
}
}()
<-exit
if !passed {
t.Fail()
}
}