Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
112866c3
Commit
112866c3
authored
7 years ago
by
Steven Allen
Browse files
Options
Download
Email Patches
Plain Diff
tests: update test cases to act like go-peerstream 1.7.0
parent
d50c54fe
master
2018-Q4-OKR
feat/protobuf
feat/udp
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
p2p/net/mock/mock_notif_test.go
+10
-9
p2p/net/mock/mock_notif_test.go
p2p/net/mock/mock_peernet.go
+10
-4
p2p/net/mock/mock_peernet.go
with
20 additions
and
13 deletions
+20
-13
p2p/net/mock/mock_notif_test.go
View file @
112866c3
...
...
@@ -11,8 +11,9 @@ import (
)
func
TestNotifications
(
t
*
testing
.
T
)
{
const
swarmSize
=
5
mn
,
err
:=
FullMeshLinked
(
context
.
Background
(),
5
)
mn
,
err
:=
FullMeshLinked
(
context
.
Background
(),
swarmSize
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -23,7 +24,7 @@ func TestNotifications(t *testing.T) {
nets
:=
mn
.
Nets
()
notifiees
:=
make
([]
*
netNotifiee
,
len
(
nets
))
for
i
,
pn
:=
range
nets
{
n
:=
newNetNotifiee
()
n
:=
newNetNotifiee
(
swarmSize
)
pn
.
Notify
(
n
)
notifiees
[
i
]
=
n
}
...
...
@@ -193,14 +194,14 @@ type netNotifiee struct {
closedStream
chan
inet
.
Stream
}
func
newNetNotifiee
()
*
netNotifiee
{
func
newNetNotifiee
(
buffer
int
)
*
netNotifiee
{
return
&
netNotifiee
{
listen
:
make
(
chan
ma
.
Multiaddr
),
listenClose
:
make
(
chan
ma
.
Multiaddr
),
connected
:
make
(
chan
inet
.
Conn
),
disconnected
:
make
(
chan
inet
.
Conn
),
openedStream
:
make
(
chan
inet
.
Stream
),
closedStream
:
make
(
chan
inet
.
Stream
),
listen
:
make
(
chan
ma
.
Multiaddr
,
buffer
),
listenClose
:
make
(
chan
ma
.
Multiaddr
,
buffer
),
connected
:
make
(
chan
inet
.
Conn
,
buffer
),
disconnected
:
make
(
chan
inet
.
Conn
,
buffer
),
openedStream
:
make
(
chan
inet
.
Stream
,
buffer
),
closedStream
:
make
(
chan
inet
.
Stream
,
buffer
),
}
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_peernet.go
View file @
112866c3
...
...
@@ -31,7 +31,7 @@ type peernet struct {
streamHandler
inet
.
StreamHandler
connHandler
inet
.
ConnHandler
notifmu
sync
.
RW
Mutex
notifmu
sync
.
Mutex
notifs
map
[
inet
.
Notifiee
]
struct
{}
proc
goprocess
.
Process
...
...
@@ -381,11 +381,17 @@ func (pn *peernet) StopNotify(f inet.Notifiee) {
// notifyAll runs the notification function on all Notifiees
func
(
pn
*
peernet
)
notifyAll
(
notification
func
(
f
inet
.
Notifiee
))
{
pn
.
notifmu
.
RLock
()
pn
.
notifmu
.
Lock
()
var
wg
sync
.
WaitGroup
for
n
:=
range
pn
.
notifs
{
// make sure we dont block
// and they dont block each other.
go
notification
(
n
)
wg
.
Add
(
1
)
go
func
(
n
inet
.
Notifiee
)
{
defer
wg
.
Done
()
notification
(
n
)
}(
n
)
}
pn
.
notifmu
.
RUnlock
()
wg
.
Wait
()
pn
.
notifmu
.
Unlock
()
}
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help