(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestCreateBlockBoundaries(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | queryShards int |
| 16 | expected [][]byte |
| 17 | }{ |
| 18 | { |
| 19 | name: "single shard", |
| 20 | queryShards: 1, |
| 21 | expected: [][]byte{ |
| 22 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 23 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, |
| 24 | }, |
| 25 | }, |
| 26 | { |
| 27 | name: "multiple shards", |
| 28 | queryShards: 4, |
| 29 | expected: [][]byte{ |
| 30 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 31 | {0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 32 | {0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 33 | {0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 34 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, |
| 35 | }, |
| 36 | }, |
| 37 | { |
| 38 | name: "large number of evenly divisible shards", |
| 39 | queryShards: 255, |
| 40 | }, |
| 41 | { |
| 42 | name: "large number of not evenly divisible shards", |
| 43 | queryShards: 1111, |
| 44 | }, |
| 45 | } |
| 46 | for _, tt := range tests { |
| 47 | t.Run(tt.name, func(t *testing.T) { |
| 48 | bb := CreateBlockBoundaries(tt.queryShards) |
| 49 | |
| 50 | if len(tt.expected) > 0 { |
| 51 | require.Len(t, bb, len(tt.expected)) |
| 52 | for i := 0; i < len(bb); i++ { |
| 53 | require.Equal(t, tt.expected[i], bb[i]) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | maxDist := uint64(0) |
| 58 | minDist := uint64(math.MaxUint64) |
| 59 | |
| 60 | // test that the boundaries are in order |
| 61 | for i := 1; i < len(bb); i++ { |
| 62 | require.True(t, bytes.Compare(bb[i-1], bb[i]) < 0) |
| 63 | |
| 64 | prev := binary.BigEndian.Uint64(bb[i-1][:8]) |
| 65 | cur := binary.BigEndian.Uint64(bb[i][:8]) |
| 66 | dist := cur - prev |
| 67 | if dist > maxDist { |
| 68 | maxDist = dist |
| 69 | } |
nothing calls this directly
no test coverage detected