TestHandleGetRefs
The order of returned chunks is no longer guaranteed.
@@ -157,8 +157,10 @@ func TestBuildWriteValueRequest(t *testing.T) {
}
assert.Equal(len(hints), count)
- outChunkChan := make(chan interface{}, 16)
- go deserializeToChan(gr, outChunkChan)
+ outChunkChan := make(chan interface{}, len(chnx))
+ chunks.DeserializeToChan(gr, outChunkChan)
+ close(outChunkChan)
+
for c := range outChunkChan {
assert.Equal(chnx[0].Hash(), c.(*chunks.Chunk).Hash())
chnx = chnx[1:]
@@ -166,11 +168,6 @@ func TestBuildWriteValueRequest(t *testing.T) {
assert.Empty(chnx)
}
-func deserializeToChan(reader io.Reader, chunkChan chan<- interface{}) {
- chunks.DeserializeToChan(reader, chunkChan)
- close(chunkChan)
-}
-
func serializeChunks(chnx []chunks.Chunk, assert *assert.Assertions) io.Reader {
body := &bytes.Buffer{}
sw := snappy.NewBufferedWriter(body)
@@ -227,13 +224,20 @@ func TestHandleGetRefs(t *testing.T) {
)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
- chunkChan := make(chan interface{})
- go deserializeToChan(w.Body, chunkChan)
+ chunkChan := make(chan interface{}, len(chnx))
+ chunks.DeserializeToChan(w.Body, chunkChan)
+ close(chunkChan)
+
+ foundHashes := hash.HashSet{}
for c := range chunkChan {
- assert.Equal(chnx[0].Hash(), c.(*chunks.Chunk).Hash())
- chnx = chnx[1:]
+ foundHashes[c.(*chunks.Chunk).Hash()] = struct{}{}
}
- assert.Empty(chnx)
+
+ assert.True(len(foundHashes) == 2)
+ _, hasC1 := foundHashes[chnx[0].Hash()]
+ assert.True(hasC1)
+ _, hasC2 := foundHashes[chnx[1].Hash()]
+ assert.True(hasC2)
}
}
