Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
28a42ee5
Commit
28a42ee5
authored
Oct 13, 2023
by
welkin22
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use waitChan instead of sleeping
parent
07e74ee2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
sync_test.go
op-node/p2p/sync_test.go
+7
-2
No files found.
op-node/p2p/sync_test.go
View file @
28a42ee5
...
@@ -307,15 +307,19 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
...
@@ -307,15 +307,19 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
syncCl
:=
NewSyncClient
(
log
,
cfg
,
hostA
.
NewStream
,
func
(
ctx
context
.
Context
,
from
peer
.
ID
,
payload
*
eth
.
ExecutionPayload
)
error
{
syncCl
:=
NewSyncClient
(
log
,
cfg
,
hostA
.
NewStream
,
func
(
ctx
context
.
Context
,
from
peer
.
ID
,
payload
*
eth
.
ExecutionPayload
)
error
{
return
nil
return
nil
},
metrics
.
NoopMetrics
,
&
NoopApplicationScorer
{})
},
metrics
.
NoopMetrics
,
&
NoopApplicationScorer
{})
waitChan
:=
make
(
chan
struct
{},
1
)
hostA
.
Network
()
.
Notify
(
&
network
.
NotifyBundle
{
hostA
.
Network
()
.
Notify
(
&
network
.
NotifyBundle
{
ConnectedF
:
func
(
nw
network
.
Network
,
conn
network
.
Conn
)
{
ConnectedF
:
func
(
nw
network
.
Network
,
conn
network
.
Conn
)
{
syncCl
.
AddPeer
(
conn
.
RemotePeer
())
syncCl
.
AddPeer
(
conn
.
RemotePeer
())
waitChan
<-
struct
{}{}
},
},
DisconnectedF
:
func
(
nw
network
.
Network
,
conn
network
.
Conn
)
{
DisconnectedF
:
func
(
nw
network
.
Network
,
conn
network
.
Conn
)
{
// only when no connection is available, we can remove the peer
// only when no connection is available, we can remove the peer
if
nw
.
Connectedness
(
conn
.
RemotePeer
())
==
network
.
NotConnected
{
if
nw
.
Connectedness
(
conn
.
RemotePeer
())
==
network
.
NotConnected
{
syncCl
.
RemovePeer
(
conn
.
RemotePeer
())
syncCl
.
RemovePeer
(
conn
.
RemotePeer
())
}
}
waitChan
<-
struct
{}{}
},
},
})
})
syncCl
.
Start
()
syncCl
.
Start
()
...
@@ -323,8 +327,9 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
...
@@ -323,8 +327,9 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
err
=
hostA
.
Connect
(
context
.
Background
(),
peer
.
AddrInfo
{
ID
:
hostB
.
ID
(),
Addrs
:
hostB
.
Addrs
()})
err
=
hostA
.
Connect
(
context
.
Background
(),
peer
.
AddrInfo
{
ID
:
hostB
.
ID
(),
Addrs
:
hostB
.
Addrs
()})
require
.
NoError
(
t
,
err
,
"failed to connect to peer B from peer A"
)
require
.
NoError
(
t
,
err
,
"failed to connect to peer B from peer A"
)
require
.
Equal
(
t
,
hostA
.
Network
()
.
Connectedness
(
hostB
.
ID
()),
network
.
Connected
)
require
.
Equal
(
t
,
hostA
.
Network
()
.
Connectedness
(
hostB
.
ID
()),
network
.
Connected
)
//wait for async add process done
//wait for async add process done
time
.
Sleep
(
100
*
time
.
Millisecond
)
<-
waitChan
_
,
ok
:=
syncCl
.
peers
[
hostB
.
ID
()]
_
,
ok
:=
syncCl
.
peers
[
hostB
.
ID
()]
require
.
True
(
t
,
ok
,
"peerB should exist in syncClient"
)
require
.
True
(
t
,
ok
,
"peerB should exist in syncClient"
)
...
@@ -332,7 +337,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
...
@@ -332,7 +337,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
require
.
NoError
(
t
,
err
,
"close peer fail"
)
require
.
NoError
(
t
,
err
,
"close peer fail"
)
//wait for async removing process done
//wait for async removing process done
time
.
Sleep
(
100
*
time
.
Millisecond
)
<-
waitChan
_
,
peerBExist3
:=
syncCl
.
peers
[
hostB
.
ID
()]
_
,
peerBExist3
:=
syncCl
.
peers
[
hostB
.
ID
()]
require
.
True
(
t
,
!
peerBExist3
,
"peerB should not exist in syncClient"
)
require
.
True
(
t
,
!
peerBExist3
,
"peerB should not exist in syncClient"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment