Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
0c413de8
Commit
0c413de8
authored
Dec 04, 2016
by
Jeromy Johnson
Committed by
GitHub
Dec 04, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3432 from keks/feat/pubsub-sharness
add sharness test for pubsub
parents
a1d2d47a
993e7816
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
18 deletions
+69
-18
core/commands/pubsub.go
core/commands/pubsub.go
+5
-15
test/sharness/lib/iptb-lib.sh
test/sharness/lib/iptb-lib.sh
+11
-3
test/sharness/t0180-pubsub.sh
test/sharness/t0180-pubsub.sh
+53
-0
No files found.
core/commands/pubsub.go
View file @
0c413de8
...
...
@@ -122,30 +122,17 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
getPsMsgMarshaler
(
func
(
m
*
floodsub
.
Message
)
(
io
.
Reader
,
error
)
{
if
m
.
Message
==
nil
{
return
strings
.
NewReader
(
""
),
nil
}
return
bytes
.
NewReader
(
m
.
Data
),
nil
}),
"ndpayload"
:
getPsMsgMarshaler
(
func
(
m
*
floodsub
.
Message
)
(
io
.
Reader
,
error
)
{
if
m
.
Message
==
nil
{
return
strings
.
NewReader
(
"
\n
"
),
nil
}
m
.
Data
=
append
(
m
.
Data
,
'\n'
)
return
bytes
.
NewReader
(
m
.
Data
),
nil
}),
"lenpayload"
:
getPsMsgMarshaler
(
func
(
m
*
floodsub
.
Message
)
(
io
.
Reader
,
error
)
{
buf
:=
make
([]
byte
,
8
)
var
data
[]
byte
if
m
.
Message
!=
nil
{
data
=
m
.
Data
}
n
:=
binary
.
PutUvarint
(
buf
,
uint64
(
len
(
data
)))
return
io
.
MultiReader
(
bytes
.
NewReader
(
buf
[
:
n
]),
bytes
.
NewReader
(
data
)),
nil
n
:=
binary
.
PutUvarint
(
buf
,
uint64
(
len
(
m
.
Data
)))
return
io
.
MultiReader
(
bytes
.
NewReader
(
buf
[
:
n
]),
bytes
.
NewReader
(
m
.
Data
)),
nil
}),
},
Type
:
floodsub
.
Message
{},
...
...
@@ -187,6 +174,9 @@ func getPsMsgMarshaler(f func(m *floodsub.Message) (io.Reader, error)) func(cmds
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
if
obj
.
Message
==
nil
{
return
strings
.
NewReader
(
""
),
nil
}
return
f
(
obj
)
}
...
...
test/sharness/lib/iptb-lib.sh
View file @
0c413de8
...
...
@@ -19,11 +19,19 @@ check_has_connection() {
startup_cluster
()
{
num_nodes
=
"
$1
"
shift
other_args
=
"
$@
"
bound
=
$(
expr
"
$num_nodes
"
- 1
)
test_expect_success
"start up nodes"
'
iptb start
'
if
test
-n
"
$other_args
"
;
then
test_expect_success
"start up nodes with additional args"
'
iptb start --args $other_args
'
else
test_expect_success
"start up nodes"
'
iptb start
'
fi
test_expect_success
"connect nodes to eachother"
'
iptb connect [1-$bound] 0
...
...
test/sharness/t0180-pubsub.sh
0 → 100755
View file @
0c413de8
#!/bin/sh
test_description
=
"Test dht command"
.
lib/test-lib.sh
# start iptb + wait for peering
NUM_NODES
=
5
test_expect_success
'init iptb'
'
iptb init -n $NUM_NODES --bootstrap=none --port=0
'
startup_cluster
$NUM_NODES
--enable-pubsub-experiment
test_expect_success
'peer ids'
'
PEERID_0=$(iptb get id 0) &&
PEERID_2=$(iptb get id 2)
'
# ipfs pubsub sub
test_expect_success
'pubsub'
'
echo "testOK" > expected &&
touch empty &&
mkfifo wait ||
test_fsh echo init fail
# ipfs pubsub sub is long-running so we need to start it in the background and
# wait put its output somewhere where we can access it
(
ipfsi 0 pubsub sub --enc=ndpayload testTopic | if read line; then
echo $line > actual &&
echo > wait
fi
) &
# wait until ipfs pubsub sub is ready to do work
sleep 1 &&
# publish something
ipfsi 1 pubsub pub testTopic "testOK" &> pubErr &&
# wait until `echo > wait` executed
cat wait &&
test_cmp pubErr empty &&
test_cmp expected actual
'
test_expect_success
'stop iptb'
'
iptb stop
'
test_done
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