Merge lp:~axwalk/juju-core/lp1319652-instancepoller-testbatching into lp:~go-bot/juju-core/trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrew Wilkins | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 2747 | ||||
Proposed branch: | lp:~axwalk/juju-core/lp1319652-instancepoller-testbatching | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
82 lines (+46/-24) 1 file modified
worker/instancepoller/aggregate_test.go (+46/-24) |
||||
To merge this branch: | bzr merge lp:~axwalk/juju-core/lp1319652-instancepoller-testbatching | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+220014@code.launchpad.net |
Commit message
worker/
The existing TestBatching test was very prone to
failure due to the nature of the test. The test
ensures that requests to Instances are batched
using a token bucket.
Whereas the existing test streamed requests, the
new implementation compresses the addition of
requests into the point where we service an
Instances call. We can thus reliably determine
the number of batches that will be made, as calls
to Instances must complete before additional
requests are gathered.
Fixes lp:1319652
Description of the change
worker/
The existing TestBatching test was very prone to
failure due to the nature of the test. The test
ensures that requests to Instances are batched
using a token bucket.
Whereas the existing test streamed requests, the
new implementation compresses the addition of
requests into the point where we service an
Instances call. We can thus reliably determine
the number of batches that will be made, as calls
to Instances must complete before additional
requests are gathered.
Fixes lp:1319652
Reviewers: mp+220014_ code.launchpad. net,
Message:
Please take a look.
Description: instancepoller: TestBatching less race-y
worker/
The existing TestBatching test was very prone to
failure due to the nature of the test. The test
ensures that requests to Instances are batched
using a token bucket.
Whereas the existing test streamed requests, the
new implementation compresses the addition of
requests into the point where we service an
Instances call. We can thus reliably determine
the number of batches that will be made, as calls
to Instances must complete before additional
requests are gathered.
Fixes lp:1319652
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1319652- instancepoller- testbatching/ +merge/ 220014
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/96440043/
Affected files (+48, -24 lines): instancepoller/ aggregate_ test.go
A [revision details]
M worker/
Index: [revision details] 20140519073812- 9ribeb9ud0q2glc o
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: worker/ instancepoller/ aggregate_ test.go instancepoller/ aggregate_ test.go' instancepoller/ aggregate_ test.go 2014-05-13 06:12:51 +0000 instancepoller/ aggregate_ test.go 2014-05-19 11:11:39 +0000 len(testGetter. ids), gc.DeepEquals, 2)
=== modified file 'worker/
--- worker/
+++ worker/
@@ -116,32 +116,54 @@
c.Assert(
}
+type batchingInstanc eGetter struct { ceGetter) Instances(ids []instance.Id) Instance, error) { etter.Instances (ids) ceGetter) startRequests() { ceGetter) startRequest() { instanceInfo( "foo") (&gatherTime, 10*time. Millisecond) eGetter) testGetter) testGetter. results, ("foobar" , []string{ "127.0. 0.1", "192.168.1.1"})) instanceInfo( "foo") time.Millisecon d) ).Sub(startTime ) testGetter. counter, jc.LessThan, expectedMax+1) testGetter. counter, jc.GreaterThan, 10)
+ testInstanceGetter
+ wg sync.WaitGroup
+ aggregator *aggregator
+ batchSize int
+ started int
+}
+
+func (g *batchingInstan
([]instance.
+ insts, err := g.testInstanceG
+ g.startRequests()
+ return insts, err
+}
+
+func (g *batchingInstan
+ n := len(g.results) - g.started
+ if n > g.batchSize {
+ n = g.batchSize
+ }
+ for i := 0; i < n; i++ {
+ g.startRequest()
+ }
+}
+
+func (g *batchingInstan
+ g.started++
+ go func() {
+ _, err := g.aggregator.
+ if err != nil {
+ panic(err)
+ }
+ g.wg.Done()
+ }()
+}
+
func (s *aggregateSuite) TestBatching(c *gc.C) {
s.PatchValue
- testGetter := new(testInstanc
-
- aggregator := newAggregator(
- for i := 0; i < 100; i++ {
- testGetter.results = append(
newTestInstance
- }
- var wg sync.WaitGroup
- makeRequest := func() {
- _, err := aggregator.
- c.Check(err, gc.IsNil)
- wg.Done()
- }
- startTime := time.Now()
- wg.Add(100)
- for i := 0; i < 100; i++ {
- go makeRequest()
- time.Sleep(
- }
- wg.Wait()
- totalTime := time.Now(
- // +1 because we expect one extra call for the first request
- expectedMax := int32((totalTime / (10 * time.Millisecond)) + 1)
- c.Assert(
- c.Assert(
+ var testGetter...