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

Function TestMethod_Throttling

method_test.go:11–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func 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
57func TestMethod_Latest(t *testing.T) {
58 k := New("testkite", "0.0.1")

Callers

nothing calls this directly

Calls 10

DialMethod · 0.95
TellWithTimeoutMethod · 0.95
ThrottleMethod · 0.80
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