MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestChannelReceive

Function TestChannelReceive

pkg/events/handler_test.go:78–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

76}
77
78func TestChannelReceive(t *testing.T) {
79 t.Parallel()
80 a := assertions.New(t)
81
82 eventChan := make(events.Channel, 2)
83 eventChan.Notify(events.New(test.Context(), "evt", "event"))
84 eventChan.Notify(events.New(test.Context(), "evt", "event"))
85 eventChan.Notify(events.New(test.Context(), "overflow", "this overflows the channel"))
86
87 runtime.Gosched()
88
89 ctx, cancel := context.WithCancel(test.Context())
90
91 a.So(eventChan.ReceiveTimeout(test.Delay), should.NotBeNil)
92 a.So(eventChan.ReceiveContext(ctx), should.NotBeNil)
93
94 cancel()
95
96 a.So(eventChan.ReceiveTimeout(test.Delay), should.BeNil)
97 a.So(eventChan.ReceiveContext(ctx), should.BeNil)
98}
99
100func ExampleContextHandler() {
101 // Usually the context comes from somewhere else (e.g. a streaming RPC):

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
ContextFunction · 0.92
ReceiveTimeoutMethod · 0.80
ReceiveContextMethod · 0.80
NewMethod · 0.65
NotifyMethod · 0.65

Tested by

no test coverage detected