MCPcopy Index your code
hub / github.com/koding/kite / TestContext

Function TestContext

kite_test.go:48–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestContext(t *testing.T) {
49 flag.Parse()
50
51 ch := make(chan int, 4) // checkpoints, to ensure correct control flow
52
53 k := New("server", "0.0.1")
54 k.Config.DisableAuthentication = true
55 k.Config.Port = 3333
56 k.Config.Transport = transportFromEnv()
57 k.HandleFunc("longrunning", func(r *Request) (interface{}, error) {
58 ch <- 2
59
60 go func() {
61 <-r.Context.Done()
62 ch <- 4
63 }()
64 return nil, nil
65 })
66 go k.Run()
67 <-k.ServerReadyNotify()
68 defer k.Close()
69
70 c := New("client", "0.0.1").NewClient("http://127.0.0.1:3333/kite")
71 if err := c.Dial(); err != nil {
72 t.Fatalf("Dial()=%s", err)
73 }
74
75 ch <- 1
76
77 if _, err := c.TellWithTimeout("longrunning", *timeout); err != nil {
78 t.Fatalf("TellWithTimeout()=%s", err)
79 }
80
81 ch <- 3
82
83 c.Close()
84
85 var got []int
86 want := []int{1, 2, 3, 4}
87 timeout := time.After(2 * time.Second)
88
89 for len(got) != len(want) {
90 select {
91 case i := <-ch:
92 got = append(got, i)
93 case <-timeout:
94 t.Fatal("timed out collecting checkpoints")
95 }
96 }
97
98 if !reflect.DeepEqual(got, want) {
99 t.Fatalf("got %v, want %v", got, want)
100 }
101}
102
103func TestMultiple(t *testing.T) {
104 testDuration := time.Second * 10

Callers

nothing calls this directly

Calls 11

DialMethod · 0.95
TellWithTimeoutMethod · 0.95
CloseMethod · 0.95
transportFromEnvFunction · 0.85
HandleFuncMethod · 0.80
ServerReadyNotifyMethod · 0.80
NewClientMethod · 0.80
FatalMethod · 0.80
NewFunction · 0.70
RunMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected