aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
authorAdam Babik <a.babik@designfortress.com>2018-08-29 18:56:13 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-29 18:56:13 +0800
commit75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d (patch)
treeb4bfd05a88e02a103f4847546a084be31cbae223 /whisper
parent957496811627d6ef33b9b4232e4d42353d376f1d (diff)
downloadgo-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar.gz
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar.bz2
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar.lz
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar.xz
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.tar.zst
go-tangerine-75ae5af62a8dbbc4fc547d2b3b4cce192d783b2d.zip
whisper: fix loop in expire() (#17532)
Diffstat (limited to 'whisper')
-rw-r--r--whisper/whisperv5/whisper.go2
-rw-r--r--whisper/whisperv5/whisper_test.go33
-rw-r--r--whisper/whisperv6/whisper.go2
-rw-r--r--whisper/whisperv6/whisper_test.go33
4 files changed, 42 insertions, 28 deletions
diff --git a/whisper/whisperv5/whisper.go b/whisper/whisperv5/whisper.go
index 8e0662327..465545821 100644
--- a/whisper/whisperv5/whisper.go
+++ b/whisper/whisperv5/whisper.go
@@ -717,7 +717,7 @@ func (w *Whisper) expire() {
w.stats.messagesCleared++
w.stats.memoryCleared += sz
w.stats.memoryUsed -= sz
- return true
+ return false
})
w.expirations[expiry].Clear()
delete(w.expirations, expiry)
diff --git a/whisper/whisperv5/whisper_test.go b/whisper/whisperv5/whisper_test.go
index 8af085292..a7bd17e4d 100644
--- a/whisper/whisperv5/whisper_test.go
+++ b/whisper/whisperv5/whisper_test.go
@@ -487,27 +487,34 @@ func TestExpiry(t *testing.T) {
if err != nil {
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
}
-
params.TTL = 1
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- err = w.Send(env)
- if err != nil {
- t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
+ messagesCount := 5
+
+ // Send a few messages one after another. Due to low PoW and expiration buckets
+ // with one second resolution, it covers a case when there are multiple items
+ // in a single expiration bucket.
+ for i := 0; i < messagesCount; i++ {
+ msg, err := NewSentMessage(params)
+ if err != nil {
+ t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
+ }
+ env, err := msg.Wrap(params)
+ if err != nil {
+ t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+
+ err = w.Send(env)
+ if err != nil {
+ t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
+ }
}
// wait till received or timeout
var received, expired bool
for j := 0; j < 20; j++ {
time.Sleep(100 * time.Millisecond)
- if len(w.Envelopes()) > 0 {
+ if len(w.Envelopes()) == messagesCount {
received = true
break
}
diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go
index 34c1256a6..be633e7ff 100644
--- a/whisper/whisperv6/whisper.go
+++ b/whisper/whisperv6/whisper.go
@@ -900,7 +900,7 @@ func (whisper *Whisper) expire() {
whisper.stats.messagesCleared++
whisper.stats.memoryCleared += sz
whisper.stats.memoryUsed -= sz
- return true
+ return false
})
whisper.expirations[expiry].Clear()
delete(whisper.expirations, expiry)
diff --git a/whisper/whisperv6/whisper_test.go b/whisper/whisperv6/whisper_test.go
index 7fe256309..895bb2b96 100644
--- a/whisper/whisperv6/whisper_test.go
+++ b/whisper/whisperv6/whisper_test.go
@@ -465,27 +465,34 @@ func TestExpiry(t *testing.T) {
if err != nil {
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
}
-
params.TTL = 1
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- err = w.Send(env)
- if err != nil {
- t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
+ messagesCount := 5
+
+ // Send a few messages one after another. Due to low PoW and expiration buckets
+ // with one second resolution, it covers a case when there are multiple items
+ // in a single expiration bucket.
+ for i := 0; i < messagesCount; i++ {
+ msg, err := NewSentMessage(params)
+ if err != nil {
+ t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
+ }
+ env, err := msg.Wrap(params)
+ if err != nil {
+ t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+
+ err = w.Send(env)
+ if err != nil {
+ t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
+ }
}
// wait till received or timeout
var received, expired bool
for j := 0; j < 20; j++ {
time.Sleep(100 * time.Millisecond)
- if len(w.Envelopes()) > 0 {
+ if len(w.Envelopes()) == messagesCount {
received = true
break
}