1package imapserver
2
3import (
4 "fmt"
5 "testing"
6 "time"
7
8 "github.com/mjl-/mox/imapclient"
9)
10
11func TestIdle(t *testing.T) {
12 tc1 := start(t)
13 defer tc1.close()
14 tc1.client.Login("mjl@mox.example", password0)
15
16 tc2 := startNoSwitchboard(t)
17 defer tc2.close()
18 tc2.client.Login("mjl@mox.example", password0)
19
20 tc1.transactf("ok", "select inbox")
21 tc2.transactf("ok", "select inbox")
22
23 // todo: test with delivery through smtp
24
25 tc2.cmdf("", "idle")
26 tc2.readprefixline("+ ")
27 done := make(chan error)
28 go func() {
29 defer func() {
30 x := recover()
31 if x != nil {
32 done <- fmt.Errorf("%v", x)
33 }
34 }()
35 untagged, _ := tc2.client.ReadUntagged()
36 var exists imapclient.UntaggedExists
37 tuntagged(tc2.t, untagged, &exists)
38 // todo: validate the data we got back.
39 tc2.writelinef("done")
40 done <- nil
41 }()
42
43 tc1.transactf("ok", "append inbox () {%d+}\r\n%s", len(exampleMsg), exampleMsg)
44 timer := time.NewTimer(time.Second)
45 defer timer.Stop()
46 select {
47 case err := <-done:
48 tc1.check(err, "idle")
49 case <-timer.C:
50 t.Fatalf("idle did not finish")
51 }
52}
53