import "time"
(t *testing.T, groups []int, ck *Clerk)
| 10 | // import "time" |
| 11 | |
| 12 | func check(t *testing.T, groups []int, ck *Clerk) { |
| 13 | c := ck.Query(-1) |
| 14 | if len(c.Groups) != len(groups) { |
| 15 | t.Fatalf("wanted %v groups, got %v", len(groups), len(c.Groups)) |
| 16 | } |
| 17 | |
| 18 | // are the groups as expected? |
| 19 | for _, g := range groups { |
| 20 | _, ok := c.Groups[g] |
| 21 | if ok != true { |
| 22 | t.Fatalf("missing group %v", g) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // any un-allocated shards? |
| 27 | if len(groups) > 0 { |
| 28 | for s, g := range c.Shards { |
| 29 | _, ok := c.Groups[g] |
| 30 | if ok == false { |
| 31 | t.Fatalf("shard %v -> invalid group %v", s, g) |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // more or less balanced sharding? |
| 37 | counts := map[int]int{} |
| 38 | for _, g := range c.Shards { |
| 39 | counts[g] += 1 |
| 40 | } |
| 41 | min := 257 |
| 42 | max := 0 |
| 43 | for g, _ := range c.Groups { |
| 44 | if counts[g] > max { |
| 45 | max = counts[g] |
| 46 | } |
| 47 | if counts[g] < min { |
| 48 | min = counts[g] |
| 49 | } |
| 50 | } |
| 51 | if max > min+1 { |
| 52 | t.Fatalf("max %v too much larger than min %v", max, min) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func check_same_config(t *testing.T, c1 Config, c2 Config) { |
| 57 | if c1.Num != c2.Num { |