(t *testing.T)
| 46 | } |
| 47 | |
| 48 | func 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 | |
| 103 | func TestMultiple(t *testing.T) { |
| 104 | testDuration := time.Second * 10 |
nothing calls this directly
no test coverage detected