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