Files
go-sip/cmd/sip-go-agent/identity_watch_test.go
T

43 lines
1.0 KiB
Go

package main
import (
"context"
"errors"
"testing"
"time"
amqp "github.com/rabbitmq/amqp091-go"
)
func TestDispatcherIdentityLossCancelsAdmissionContext(t *testing.T) {
for _, closed := range []bool{false, true} {
done := make(chan *amqp.Error, 1)
ctx, cancel := dispatcherIdentityContext(context.Background(), done)
if closed {
close(done)
} else {
done <- &amqp.Error{Code: 320, Reason: "local test disconnect"}
}
select {
case <-ctx.Done():
case <-time.After(time.Second):
t.Fatal("identity loss did not stop admission")
}
if !errors.Is(context.Cause(ctx), errDispatcherIdentityLost) {
t.Fatalf("lost cause: %v", context.Cause(ctx))
}
cancel()
}
}
func TestDispatcherIdentityWatchStopsWithParent(t *testing.T) {
parent, cancelParent := context.WithCancel(context.Background())
ctx, cancel := dispatcherIdentityContext(parent, make(chan *amqp.Error))
defer cancel()
cancelParent()
<-ctx.Done()
if !errors.Is(context.Cause(ctx), context.Canceled) {
t.Fatal("normal cancellation reported identity loss")
}
}