mox/imapserver/idle_test.go
Mechiel Lukkien e5eaf4d46f
Some checks are pending
Build and test / build-test (oldstable) (push) Waiting to run
Build and test / build-test (stable) (push) Waiting to run
fix race in imapserver tests
2024-12-25 16:50:23 +01:00

53 lines
1 KiB
Go

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()
tc1.client.Login("mjl@mox.example", password0)
tc2.client.Login("mjl@mox.example", password0)
tc1.transactf("ok", "select inbox")
tc2.transactf("ok", "select inbox")
// todo: test with delivery through smtp
tc2.cmdf("", "idle")
tc2.readprefixline("+ ")
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")
}
}