good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
bcf41797
Commit
bcf41797
authored
Apr 15, 2015
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
whisper: global message expiration tests, polishes
parent
4fb7ab5d
Branches
Branches containing commit
Tags
v1.6.1
v1.6.2
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
whisper/common_test.go
+1
-2
1 addition, 2 deletions
whisper/common_test.go
whisper/peer_test.go
+22
-14
22 additions, 14 deletions
whisper/peer_test.go
whisper/whisper_test.go
+26
-0
26 additions, 0 deletions
whisper/whisper_test.go
with
49 additions
and
16 deletions
whisper/common_test.go
+
1
−
2
View file @
bcf41797
...
@@ -8,9 +8,8 @@ import (
...
@@ -8,9 +8,8 @@ import (
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discover"
)
)
...
...
This diff is collapsed.
Click to expand it.
whisper/peer_test.go
+
22
−
14
View file @
bcf41797
...
@@ -38,6 +38,20 @@ func startTestPeer() *testPeer {
...
@@ -38,6 +38,20 @@ func startTestPeer() *testPeer {
}
}
}
}
func
startTestPeerInited
()
(
*
testPeer
,
error
)
{
peer
:=
startTestPeer
()
if
err
:=
p2p
.
ExpectMsg
(
peer
.
stream
,
statusCode
,
[]
uint64
{
protocolVersion
});
err
!=
nil
{
peer
.
stream
.
Close
()
return
nil
,
err
}
if
err
:=
p2p
.
SendItems
(
peer
.
stream
,
statusCode
,
protocolVersion
);
err
!=
nil
{
peer
.
stream
.
Close
()
return
nil
,
err
}
return
peer
,
nil
}
func
TestPeerStatusMessage
(
t
*
testing
.
T
)
{
func
TestPeerStatusMessage
(
t
*
testing
.
T
)
{
tester
:=
startTestPeer
()
tester
:=
startTestPeer
()
...
@@ -102,15 +116,12 @@ func TestPeerHandshakeSuccess(t *testing.T) {
...
@@ -102,15 +116,12 @@ func TestPeerHandshakeSuccess(t *testing.T) {
func
TestPeerSend
(
t
*
testing
.
T
)
{
func
TestPeerSend
(
t
*
testing
.
T
)
{
// Start a tester and execute the handshake
// Start a tester and execute the handshake
tester
:=
startTestPeer
()
tester
,
err
:=
startTestPeerInited
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to start initialized peer: %v"
,
err
)
}
defer
tester
.
stream
.
Close
()
defer
tester
.
stream
.
Close
()
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
statusCode
,
[]
uint64
{
protocolVersion
});
err
!=
nil
{
t
.
Fatalf
(
"status message mismatch: %v"
,
err
)
}
if
err
:=
p2p
.
SendItems
(
tester
.
stream
,
statusCode
,
protocolVersion
);
err
!=
nil
{
t
.
Fatalf
(
"failed to send status: %v"
,
err
)
}
// Construct a message and inject into the tester
// Construct a message and inject into the tester
message
:=
NewMessage
([]
byte
(
"peer broadcast test message"
))
message
:=
NewMessage
([]
byte
(
"peer broadcast test message"
))
envelope
,
err
:=
message
.
Wrap
(
DefaultPoW
,
Options
{
envelope
,
err
:=
message
.
Wrap
(
DefaultPoW
,
Options
{
...
@@ -138,15 +149,12 @@ func TestPeerSend(t *testing.T) {
...
@@ -138,15 +149,12 @@ func TestPeerSend(t *testing.T) {
func
TestPeerDeliver
(
t
*
testing
.
T
)
{
func
TestPeerDeliver
(
t
*
testing
.
T
)
{
// Start a tester and execute the handshake
// Start a tester and execute the handshake
tester
:=
startTestPeer
()
tester
,
err
:=
startTestPeerInited
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to start initialized peer: %v"
,
err
)
}
defer
tester
.
stream
.
Close
()
defer
tester
.
stream
.
Close
()
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
statusCode
,
[]
uint64
{
protocolVersion
});
err
!=
nil
{
t
.
Fatalf
(
"status message mismatch: %v"
,
err
)
}
if
err
:=
p2p
.
SendItems
(
tester
.
stream
,
statusCode
,
protocolVersion
);
err
!=
nil
{
t
.
Fatalf
(
"failed to send status: %v"
,
err
)
}
// Watch for all inbound messages
// Watch for all inbound messages
arrived
:=
make
(
chan
struct
{},
1
)
arrived
:=
make
(
chan
struct
{},
1
)
tester
.
client
.
Watch
(
Filter
{
tester
.
client
.
Watch
(
Filter
{
...
...
This diff is collapsed.
Click to expand it.
whisper/whisper_test.go
+
26
−
0
View file @
bcf41797
...
@@ -156,3 +156,29 @@ func testBroadcast(anonymous bool, t *testing.T) {
...
@@ -156,3 +156,29 @@ func testBroadcast(anonymous bool, t *testing.T) {
}
}
}
}
}
}
func
TestMessageExpiration
(
t
*
testing
.
T
)
{
// Start the single node cluster and inject a dummy message
node
:=
startTestCluster
(
1
)[
0
]
message
:=
NewMessage
([]
byte
(
"expiring message"
))
envelope
,
err
:=
message
.
Wrap
(
DefaultPoW
,
Options
{
TTL
:
time
.
Second
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to wrap message: %v"
,
err
)
}
if
err
:=
node
.
Send
(
envelope
);
err
!=
nil
{
t
.
Fatalf
(
"failed to inject message: %v"
,
err
)
}
// Check that the message is inside the cache
if
_
,
ok
:=
node
.
messages
[
envelope
.
Hash
()];
!
ok
{
t
.
Fatalf
(
"message not found in cache"
)
}
// Wait for expiration and check cache again
time
.
Sleep
(
time
.
Second
)
// wait for expiration
time
.
Sleep
(
expirationTicks
)
// wait for cleanup cycle
if
_
,
ok
:=
node
.
messages
[
envelope
.
Hash
()];
ok
{
t
.
Fatalf
(
"message not expired from cache"
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment