mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
5336032088
so users can easily take their email out of somewhere else, and import it into mox. this goes a little way to give feedback as the import progresses: upload progress is shown (surprisingly, browsers aren't doing this...), imported mailboxes/messages are counted (batched) and import issues/warnings are displayed, all sent over an SSE connection. an import token is stored in sessionstorage. if you reload the page (e.g. after a connection error), the browser will reconnect to the running import and show its progress again. and you can just abort the import before it is finished and committed, and nothing will have changed. this also imports flags/keywords from mbox files.
46 lines
927 B
Go
46 lines
927 B
Go
package mox
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
func TestLifecycle(t *testing.T) {
|
|
Shutdown, ShutdownCancel = context.WithCancel(context.Background())
|
|
c := &connections{
|
|
conns: map[net.Conn]connKind{},
|
|
gauges: map[connKind]prometheus.GaugeFunc{},
|
|
active: map[connKind]int64{},
|
|
}
|
|
nc0, nc1 := net.Pipe()
|
|
defer nc0.Close()
|
|
defer nc1.Close()
|
|
c.Register(nc0, "proto", "listener")
|
|
c.Shutdown()
|
|
|
|
done := c.Done()
|
|
select {
|
|
case <-done:
|
|
t.Fatalf("already done, but still a connection open")
|
|
default:
|
|
}
|
|
|
|
_, err := nc0.Read(make([]byte, 1))
|
|
if err == nil {
|
|
t.Fatalf("expected i/o deadline exceeded, got no error")
|
|
}
|
|
if !errors.Is(err, os.ErrDeadlineExceeded) {
|
|
t.Fatalf("got %v, expected os.ErrDeadlineExceeded", err)
|
|
}
|
|
c.Unregister(nc0)
|
|
select {
|
|
case <-done:
|
|
default:
|
|
t.Fatalf("unregistered connection, but not yet done")
|
|
}
|
|
}
|