fix pubsub pub reading stdin args
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Mar 5, 2018 at 11:00 UTC
dd40a5a2d5cafa37f25336f2026d194a097d3c7e
2 files changed
+37
-1
core/commands/pubsub.go
+6
@@ -223,6 +223,12 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
223
224
topic := req.Arguments[0]
225
226
+ err = req.ParseBodyArgs()
227
+ if err != nil && !cmds.IsAllArgsAlreadyCovered(err) {
228
+ res.SetError(err, cmdkit.ErrNormal)
229
+ return
230
+ }
231
+
232
for _, data := range req.Arguments[1:] {
233
if err := n.Floodsub.Publish(topic, []byte(data)); err != nil {
234
res.SetError(err, cmdkit.ErrNormal)
test/sharness/t0180-pubsub.sh
+31
-1
@@ -35,7 +35,7 @@ test_expect_success 'pubsub' '
35
'
36
37
test_expect_success "wait until ipfs pubsub sub is ready to do work" '
38
- sleep 1
38
+ go-sleep 500ms
39
'
40
41
test_expect_success "can see peer subscribed to testTopic" '
@@ -57,6 +57,36 @@ test_expect_success "wait until echo > wait executed" '
57
test_cmp expected actual
58
'
59
60
+test_expect_success "wait for another pubsub message" '
61
+ echo "testOK2" > expected &&
62
+ mkfifo wait2 ||
63
+ test_fsh echo init fail
64
+
65
+ # ipfs pubsub sub is long-running so we need to start it in the background and
66
+ # wait put its output somewhere where we can access it
67
+ (
68
+ ipfsi 2 pubsub sub --enc=ndpayload testTopic | if read line; then
69
+ echo $line > actual &&
70
+ echo > wait2
71
+ fi
72
+ ) &
73
+'
74
+
75
+test_expect_success "wait until ipfs pubsub sub is ready to do work" '
76
+ go-sleep 500ms
77
+'
78
+
79
+test_expect_success "publish something" '
80
+ echo "testOK2" | ipfsi 1 pubsub pub testTopic &> pubErr
81
+'
82
+
83
+test_expect_success "wait until echo > wait executed" '
84
+ echo "testOK2" > expected &&
85
+ cat wait2 &&
86
+ test_cmp pubErr empty &&
87
+ test_cmp expected actual
88
+'
89
+
90
test_expect_success 'stop iptb' '
91
iptb stop
92
'