MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestHandler_DrainUnreadOnConnect

Function TestHandler_DrainUnreadOnConnect

internal/ws/handler_test.go:282–371  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestHandler_DrainUnreadOnConnect(t *testing.T) {
283 hub := NewHub()
284 defer hub.Close()
285
286 now := time.Now()
287 store := &mockStore{
288 user: newTestUser(),
289 agent: newTestAgent("user_1"),
290 messages: []identity.Message{
291 {
292 ID: "msg_1",
293 AgentID: "agent_test",
294 Sender: "alice@example.com",
295 Recipient: "bot@agents.e2a.dev",
296 Subject: "Hello",
297 ConversationID: "conv_1",
298 CreatedAt: now,
299 },
300 {
301 ID: "msg_2",
302 AgentID: "agent_test",
303 Sender: "bob@example.com",
304 Recipient: "bot@agents.e2a.dev",
305 Subject: "Hi there",
306 CreatedAt: now,
307 },
308 },
309 }
310 handler := NewHandler(hub, store)
311 srv := startServer(t, handler)
312
313 conn, _ := dialWS(t, srv, "bot@agents.e2a.dev", "valid_key")
314 if conn == nil {
315 t.Fatal("expected successful WS connection")
316 }
317 defer conn.Close(websocket.StatusNormalClosure, "")
318
319 // Read two drained notifications
320 for i := 0; i < 2; i++ {
321 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
322 _, data, err := conn.Read(ctx)
323 cancel()
324 if err != nil {
325 t.Fatalf("read notification %d: %v", i+1, err)
326 }
327
328 var notif struct {
329 MessageID string `json:"message_id"`
330 ConversationID string `json:"conversation_id,omitempty"`
331 From string `json:"from"`
332 Recipient string `json:"recipient"`
333 Subject string `json:"subject"`
334 }
335 if err := json.Unmarshal(data, &notif); err != nil {
336 t.Fatalf("unmarshal notification %d: %v", i+1, err)
337 }
338
339 if i == 0 {

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
NewHubFunction · 0.85
newTestUserFunction · 0.85
newTestAgentFunction · 0.85
NewHandlerFunction · 0.85
startServerFunction · 0.85
dialWSFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected