(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestMethod_Throttling(t *testing.T) { |
| 12 | k := New("testkite", "0.0.1") |
| 13 | k.Config.DisableAuthentication = true |
| 14 | k.Config.Port = 9996 |
| 15 | |
| 16 | k.HandleFunc("foo", func(r *Request) (interface{}, error) { |
| 17 | return "handle", nil |
| 18 | }).Throttle(time.Second*2, 30) |
| 19 | |
| 20 | go k.Run() |
| 21 | defer k.Close() |
| 22 | <-k.ServerReadyNotify() |
| 23 | |
| 24 | c := New("exp", "0.0.1").NewClient("http://127.0.0.1:9996/kite") |
| 25 | if err := c.Dial(); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | |
| 29 | // First let us exhaust the bucket |
| 30 | for i := 0; i < 20; i++ { |
| 31 | _, err := c.TellWithTimeout("foo", 4*time.Second) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // now, the request 21 should give a requestLimitError |
| 38 | _, err := c.TellWithTimeout("foo", 4*time.Second) |
| 39 | if err != nil { |
| 40 | if kErr, ok := err.(*Error); ok { |
| 41 | if kErr.Type != "requestLimitError" { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // now wait until the bucket is filled again |
| 48 | time.Sleep(time.Second * 2) |
| 49 | |
| 50 | // this shouldn't give any error at all |
| 51 | _, err = c.TellWithTimeout("foo", 4*time.Second) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestMethod_Latest(t *testing.T) { |
| 58 | k := New("testkite", "0.0.1") |
nothing calls this directly
no test coverage detected