Log notification subscription lifecycle and websocket rejections
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -17,6 +20,30 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/summarise"
|
||||
)
|
||||
|
||||
func TestAppNotificationSubscriptionLogsLifecycle(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
f := newAppNotificationFixture(t, ctx)
|
||||
var output bytes.Buffer
|
||||
previous := log.Writer()
|
||||
log.SetOutput(&output)
|
||||
t.Cleanup(func() { log.SetOutput(previous) })
|
||||
|
||||
phone := dialAckClient(t, ctx, f.url)
|
||||
subscribeNotifications(t, ctx, phone, "cursor-1")
|
||||
if !strings.Contains(output.String(), `notification subscription started request_id="sub" cursor="cursor-1"`) {
|
||||
t.Fatalf("subscription start log = %q", output.String())
|
||||
}
|
||||
phone.CloseNow()
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for !strings.Contains(output.String(), `notification subscription ended request_id="sub"`) && time.Now().Before(deadline) {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if !strings.Contains(output.String(), `notification subscription ended request_id="sub"`) || !strings.Contains(output.String(), "reason=client closed") {
|
||||
t.Fatalf("subscription end log = %q", output.String())
|
||||
}
|
||||
}
|
||||
|
||||
// appNotificationFixture is a handler over a temp store with one pipeline,
|
||||
// plus helpers to make a run end with a durable notification intent.
|
||||
type appNotificationFixture struct {
|
||||
|
||||
Reference in New Issue
Block a user