All envelopes might be delivered in multiple batches (#1483)

This commit is contained in:
Dmitry Shulyak 2019-06-08 11:04:18 +03:00 committed by GitHub
parent 79ede28ab7
commit d5a172a358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 16 deletions

View File

@ -132,17 +132,28 @@ func TestSubscriptionWhisperEnvelopes(t *testing.T) {
require.NoError(t, err)
}
var (
total int
after = time.After(2 * time.Second)
exit bool
)
for !exit {
select {
case event := <-signals:
validateShhEvent(t, event, subID, numberOfEnvelopes, topic, payload)
case <-time.After(2 * time.Second):
require.Fail(t, "timeout waiting for subscription")
total += validateShhEvent(t, event, subID, topic, payload)
if total == numberOfEnvelopes {
exit = true
}
case <-after:
exit = true
}
}
require.Equal(t, numberOfEnvelopes, total, "total number of envelopes must be equal to sent number of envelopes")
}
// * * * * * * * * * * utility methods below * * * * * * * * * * *
func validateShhEvent(t *testing.T, jsonEvent string, expectedSubID string, numberOfEnvelopes int, topic string, payload string) {
func validateShhEvent(t *testing.T, jsonEvent string, expectedSubID string, topic string, payload string) int {
result := struct {
Event signal.SubscriptionDataEvent `json:"event"`
Type string `json:"type"`
@ -153,13 +164,12 @@ func validateShhEvent(t *testing.T, jsonEvent string, expectedSubID string, numb
require.Equal(t, signal.EventSubscriptionsData, result.Type)
require.Equal(t, expectedSubID, result.Event.FilterID)
require.Equal(t, numberOfEnvelopes, len(result.Event.Data))
for _, item := range result.Event.Data {
dict := item.(map[string]interface{})
require.Equal(t, dict["topic"], topic)
require.Equal(t, dict["payload"], payload)
}
return len(result.Event.Data)
}
func validateTxEvent(t *testing.T, expectedSubID string, jsonEvent string, txID string) {