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

Function TestContextDecoupling

pkg/component/context_test.go:28–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestContextDecoupling(t *testing.T) {
29 a := assertions.New(t)
30
31 c, err := component.New(test.GetLogger(t), &component.Config{})
32 a.So(err, should.BeNil)
33
34 dl := time.Now().Add(1 * time.Second)
35
36 ctx := test.Context()
37 ctx = context.WithValue(ctx, "key", "value")
38 ctx, cancel := context.WithDeadline(ctx, dl)
39 defer cancel()
40
41 ctx = c.FromRequestContext(ctx)
42 deadline, set := ctx.Deadline()
43 a.So(deadline, should.NotEqual, dl)
44 a.So(set, should.BeFalse)
45
46 select {
47 case <-ctx.Done():
48 t.Fatal("Context expired")
49 case <-time.After(time.Second):
50 a.So(ctx.Err(), should.BeNil)
51 }
52
53 val := ctx.Value("key")
54 strVal, ok := val.(string)
55 a.So(ok, should.BeTrue)
56 a.So(strVal, should.Equal, "value")
57}

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
GetLoggerFunction · 0.92
ContextFunction · 0.92
DeadlineMethod · 0.80
DoneMethod · 0.80
AfterMethod · 0.80
NewMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65
FromRequestContextMethod · 0.65
FatalMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected