Merge lp:~dave-cheney/juju-core/124-worker-peergrouper-mock-fix into lp:~go-bot/juju-core/trunk
Proposed by
Dave Cheney
Status: | Rejected | ||||
---|---|---|---|---|---|
Rejected by: | Dave Cheney | ||||
Proposed branch: | lp:~dave-cheney/juju-core/124-worker-peergrouper-mock-fix | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
94 lines (+30/-12) 1 file modified
worker/peergrouper/mock_test.go (+30/-12) |
||||
To merge this branch: | bzr merge lp:~dave-cheney/juju-core/124-worker-peergrouper-mock-fix | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+214170@code.launchpad.net |
Description of the change
mock_test server uses fixed order
Update lp 1299958
In a previous attempt to fix this issue it was pointed out that the order of the top level is important. https:/
However the mock server does not respect any order as the fakeMachines are stored in a map.
This CL attempts to solve the problem by storing fake machines in a slice. However if you run this test repeatedly you will see the results are still not stable and in fact the test was relying on a small map to order its keys.
To post a comment you must log in.
Unmerged revisions
- 2566. By Dave Cheney
-
Mock test should order results
Reviewers: mp+214170_ code.launchpad. net,
Message:
Please take a look.
Description:
mock_test server uses fixed order
Update lp 1299958
In a previous attempt to fix this issue it was pointed out that the /codereview. appspot. com/82490043/ #msg2
order of the top level is important.
https:/
However the mock server does not respect any order as the fakeMachines
are stored in a map.
This CL attempts to solve the problem by storing fake machines in a
slice. However if you run this test repeatedly you will see the results
are still not stable and in fact the test was relying on a small map to
order its keys.
https:/ /code.launchpad .net/~dave- cheney/ juju-core/ 124-worker- peergrouper- mock-fix/ +merge/ 214170
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/84430044/
Affected files (+32, -12 lines): peergrouper/ mock_test. go
A [revision details]
M worker/
Index: [revision details] 20140404064032- dyb8bxnswgcrfxv m
=== 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/ peergrouper/ mock_test. go peergrouper/ mock_test. go' peergrouper/ mock_test. go 2014-03-28 07:27:26 +0000 peergrouper/ mock_test. go 2014-04-04 07:15:19 +0000
=== modified file 'worker/
--- worker/
+++ worker/
@@ -26,8 +26,11 @@
// that we don't want to directly depend on in unit tests.
type fakeState struct { *fakeMachine StateServerInfo
- mu sync.Mutex
- machines map[string]
+ mu sync.Mutex
+ machines []struct {
+ id string
+ *fakeMachine
+ }
stateServers voyeur.Value // of *state.
session *fakeMongoSession
check func(st *fakeState) error
@@ -105,9 +108,7 @@
}
func newFakeState() *fakeState { string] *fakeMachine) , sion(st) ers.Set( &state. StateServerInfo {})
- st := &fakeState{
- machines: make(map[
- }
+ st := new(fakeState)
st.session = newFakeMongoSes
st.stateServ
return st
@@ -171,14 +172,25 @@
func (st *fakeState) machine(id string) *fakeMachine {
st.mu.Lock()
defer st.mu.Unlock()
- return st.machines[id]
+ return st.machine0(id)
+}
+
+// machine0 is like machine but must only be called when
+// st.mu.Lock() is held.
+func (st *fakeState) machine0(id string) *fakeMachine {
+ for _, m := range st.machines {
+ if m.id == id {
+ return m.fakeMachine
+ }
+ }
+ return nil
}
func (st *fakeState) Machine(id string) (stateMachine, error) { "State. Machine" , id); err != nil { NotFoundf( "machine %s", id) Infof(" fakeState. addMachine %q", id) fmt.Errorf( "id %q already used", id))
if err := errorFor(
return nil, err
}
- if m := st.machine(id); m != nil {
+ if m := st.machine0(id); m != nil {
return m, nil
}
return nil, errors.
@@ -188,7 +200,7 @@
st.mu.Lock()
defer st.mu.Unlock()
logger.
- if st.machines[id] != nil {
+ if st.machine0(id) != nil {
panic(
}
m := &fakeMachine{
@@ -198,7 +210,10 @@
wantsVote: wantsVote,
},
}
- st.machines[id] = m
+ st.machines = append(st.machines, struct {
+ id string
+ *fakeMachine
+ }{id, m}...