2023-01-30 16:27:06 +03:00
|
|
|
package imapserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mjl-/mox/imapclient"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIdle(t *testing.T) {
|
|
|
|
tc1 := start(t)
|
|
|
|
defer tc1.close()
|
|
|
|
|
|
|
|
tc2 := startNoSwitchboard(t)
|
|
|
|
defer tc2.close()
|
2024-12-25 18:50:23 +03:00
|
|
|
|
|
|
|
tc1.client.Login("mjl@mox.example", password0)
|
2024-03-09 01:29:15 +03:00
|
|
|
tc2.client.Login("mjl@mox.example", password0)
|
2023-01-30 16:27:06 +03:00
|
|
|
|
|
|
|
tc1.transactf("ok", "select inbox")
|
|
|
|
tc2.transactf("ok", "select inbox")
|
|
|
|
|
|
|
|
// todo: test with delivery through smtp
|
|
|
|
|
|
|
|
tc2.cmdf("", "idle")
|
2023-07-24 20:54:55 +03:00
|
|
|
tc2.readprefixline("+ ")
|
2023-01-30 16:27:06 +03:00
|
|
|
done := make(chan error)
|
|
|
|
go func() {
|
|
|
|
defer func() {
|
|
|
|
x := recover()
|
|
|
|
if x != nil {
|
|
|
|
done <- fmt.Errorf("%v", x)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
untagged, _ := tc2.client.ReadUntagged()
|
|
|
|
var exists imapclient.UntaggedExists
|
|
|
|
tuntagged(tc2.t, untagged, &exists)
|
|
|
|
// todo: validate the data we got back.
|
|
|
|
tc2.writelinef("done")
|
|
|
|
done <- nil
|
|
|
|
}()
|
|
|
|
|
|
|
|
tc1.transactf("ok", "append inbox () {%d+}\r\n%s", len(exampleMsg), exampleMsg)
|
|
|
|
timer := time.NewTimer(time.Second)
|
|
|
|
defer timer.Stop()
|
|
|
|
select {
|
|
|
|
case err := <-done:
|
|
|
|
tc1.check(err, "idle")
|
|
|
|
case <-timer.C:
|
|
|
|
t.Fatalf("idle did not finish")
|
|
|
|
}
|
|
|
|
}
|