Skip to content

Commit

Permalink
Merge pull request #8 from satyrius/fix_group_by_test
Browse files Browse the repository at this point in the history
we cannot expect output channel entries order, fix #4
  • Loading branch information
satyrius committed Jul 20, 2014
2 parents e846400 + 057893f commit 1f6d220
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions reducer_test.go
Expand Up @@ -190,13 +190,18 @@ func TestGroupByReducer(t *testing.T) {
output := make(chan *Entry, 2) // Make it buffered to avoid deadlock
reducer.Reduce(input, output)

// Read and assert first group result
result, ok := <-output
assert.True(t, ok)
// Collect result entries from output channel to the map, because reading
// from channel can be in any order, it depends on each reducer processing
resultMap := make(map[string]*Entry)
for result := range output {
value, err := result.Field("host")
assert.NoError(t, err)
resultMap[value] = result
}
assert.Equal(t, len(resultMap), 2)

value, err := result.Field("host")
assert.NoError(t, err)
assert.Equal(t, value, "alpha.example.com")
// Read and assert first group result
result := resultMap["alpha.example.com"]

floatVal, err := result.FloatField("foo")
assert.NoError(t, err)
Expand All @@ -206,17 +211,12 @@ func TestGroupByReducer(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, floatVal, 2.0)

value, err = result.Field("count")
value, err := result.Field("count")
assert.NoError(t, err)
assert.Equal(t, value, "1")

// Read and assert second group result
result, ok = <-output
assert.True(t, ok)

value, err = result.Field("host")
assert.NoError(t, err)
assert.Equal(t, value, "beta.example.com")
result = resultMap["beta.example.com"]

floatVal, err = result.FloatField("foo")
assert.NoError(t, err)
Expand Down

0 comments on commit 1f6d220

Please sign in to comment.