Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(193)

Delta Between Two Patch Sets: state/apiserver/root_test.go

Issue 24040044: apiserver: analyzing ping timeouts
Left Patch Set: apiserver: analyzing ping timeouts Created 10 years, 4 months ago
Right Patch Set: apiserver: analyzing ping timeouts Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « state/apiserver/root.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package apiserver_test 4 package apiserver_test
5 5
6 import ( 6 import (
7 "time" 7 "time"
8 8
9 gc "launchpad.net/gocheck" 9 gc "launchpad.net/gocheck"
10 10
11 "launchpad.net/juju-core/rpc/rpcreflect" 11 "launchpad.net/juju-core/rpc/rpcreflect"
12 "launchpad.net/juju-core/state/apiserver" 12 "launchpad.net/juju-core/state/apiserver"
13 "launchpad.net/juju-core/testing"
13 ) 14 )
14 15
15 type rootSuite struct{} 16 type rootSuite struct{}
16 17
17 var _ = gc.Suite(&rootSuite{}) 18 var _ = gc.Suite(&rootSuite{})
18 19
19 var allowedDiscardedMethods = []string{ 20 var allowedDiscardedMethods = []string{
20 "AuthClient", 21 "AuthClient",
21 "AuthEnvironManager", 22 "AuthEnvironManager",
22 "AuthMachineAgent", 23 "AuthMachineAgent",
(...skipping 20 matching lines...) Expand all
43 c.Assert(m.ObjType.DiscardedMethods(), gc.HasLen, 0) 44 c.Assert(m.ObjType.DiscardedMethods(), gc.HasLen, 0)
44 } 45 }
45 } 46 }
46 47
47 func (r *rootSuite) TestPingTimeout(c *gc.C) { 48 func (r *rootSuite) TestPingTimeout(c *gc.C) {
48 closedc := make(chan time.Time, 1) 49 closedc := make(chan time.Time, 1)
49 action := func() { 50 action := func() {
50 closedc <- time.Now() 51 closedc <- time.Now()
51 } 52 }
52 timeout := apiserver.NewPingTimeout(action, 50*time.Millisecond) 53 timeout := apiserver.NewPingTimeout(action, 50*time.Millisecond)
53 » for i := 0; i < 10; i++ { 54 » for i := 0; i < 2; i++ {
rog 2013/11/19 14:44:08 s/10/2/ i don't think there's really any particul
mue 2013/11/19 15:52:37 Done.
54 time.Sleep(10 * time.Millisecond) 55 time.Sleep(10 * time.Millisecond)
55 timeout.Ping() 56 timeout.Ping()
56 } 57 }
57 // Expect action to be executed about 50ms after last ping. 58 // Expect action to be executed about 50ms after last ping.
58 broken := time.Now() 59 broken := time.Now()
60 var closed time.Time
59 time.Sleep(100 * time.Millisecond) 61 time.Sleep(100 * time.Millisecond)
60 » closed := <-closedc 62 » select {
rog 2013/11/19 14:44:08 select { case closed = <-closed: case <-testing.Lo
mue 2013/11/19 15:52:37 Had luck so far, but that's better.
61 » closeDiff := closed.Sub(broken).Nanoseconds() / 1000000 63 » case closed = <-closedc:
rog 2013/11/19 14:44:08 or: closeDiff := closed.Sub(broken) / time.Millise
mue 2013/11/19 15:52:37 Gnah! Sure. :)
62 » c.Assert(closeDiff >= 50 && closeDiff <= 60, gc.Equals, true) 64 » case <-time.After(testing.LongWait):
rog 2013/11/19 14:44:08 50 <= closeDiff && closeDiff <= 60 is a nice conv
mue 2013/11/19 15:52:37 Done.
65 » » c.Fatalf("action never executed")
66 » }
67 » closeDiff := closed.Sub(broken) / time.Millisecond
68 » c.Assert(50 <= closeDiff && closeDiff <= 100, gc.Equals, true)
63 } 69 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b