Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

fix flappy integration test #785

Merged
merged 5 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/inst/instance_key_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inst

import (
"encoding/json"
"sort"
"strings"
)

Expand Down Expand Up @@ -59,6 +60,9 @@ func (this *InstanceKeyMap) GetInstanceKeys() []InstanceKey {
for key := range *this {
res = append(res, key)
}
sort.Slice(res, func(i, j int) bool {
return res[i].Hostname < res[j].Hostname || res[i].Hostname == res[j].Hostname && res[i].Port < res[j].Port
})
return res
}

Expand Down
20 changes: 20 additions & 0 deletions go/inst/instance_key_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package inst

import (
"math/rand"
"testing"

"github.com/github/orchestrator/go/config"
Expand All @@ -30,6 +31,25 @@ func init() {
log.SetLevel(log.ERROR)
}

func TestGetInstanceKeys(t *testing.T) {
for range rand.Perm(10) { // Just running many iterations to cover multiple possible map iteration ordering. Perm() is just used as an array generator here.
m := *NewInstanceKeyMap()
m.AddKey(key1)
m.AddKey(key2)
keys := m.GetInstanceKeys()
test.S(t).ExpectEquals(keys[0], key1)
test.S(t).ExpectEquals(keys[1], key2)
}
for range rand.Perm(10) { // Just running many iterations to cover multiple possible map iteration ordering. Perm() is just used as an array generator here.
m := *NewInstanceKeyMap()
m.AddKey(key2)
m.AddKey(key1)
keys := m.GetInstanceKeys()
test.S(t).ExpectEquals(keys[0], key1)
test.S(t).ExpectEquals(keys[1], key2)
}
}

func TestInstanceKeyMapToJSON(t *testing.T) {
m := *NewInstanceKeyMap()
m.AddKey(key1)
Expand Down