@cryptotaxi247 / kubo / commits / 5e8725dbd

p2p: test to ensure closing right linsters

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jun 25, 2018 at 18:03 UTC 5e8725dbdeacf5c2899c76c3b36152404acd83a2
3 files changed +24 -7
core/commands/p2p.go
+8 -1
@@ -338,8 +338,15 @@ var p2pCloseCmd = &cmds.Command{
338 }
339 n.P2P.Listeners.Unlock()
340
341 + var errs []string
342 for _, l := range todo {
342 - l.Close()
343 + if err := l.Close(); err != nil {
344 + errs = append(errs, err.Error())
345 + }
346 + }
347 + if len(errs) != 0 {
348 + res.SetError(fmt.Errorf("errors when closing streams: %s", strings.Join(errs, "; ")), cmdkit.ErrNormal)
349 + return
350 }
351
352 res.SetOutput(len(todo))
p2p/local.go
+1 -2
@@ -109,8 +109,7 @@ func (l *localListener) Close() error {
109 return err
110 }
111 if ok {
112 - l.listener.Close()
113 - l.listener = nil
112 + return l.listener.Close()
113 }
114 return nil
115 }
test/sharness/t0180-p2p.sh
+15 -4
@@ -233,16 +233,27 @@ test_expect_success "'ipfs p2p close' closes app numeric handlers" '
233 test_must_be_empty actual
234 '
235
236 -test_expect_success "'ipfs p2p close' closes by listen addr" '
236 +test_expect_success "'ipfs p2p close' closes by target addr" '
237 ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
238 - ipfsi 0 p2p close -l /ipfs/$PEERID_0 &&
238 + ipfsi 0 p2p close -t /ip4/127.0.0.1/tcp/10101 &&
239 ipfsi 0 p2p ls > actual &&
240 test_must_be_empty actual
241 '
242
243 -test_expect_success "'ipfs p2p close' closes by target addr" '
243 +test_expect_success "'ipfs p2p close' closes right listeners" '
244 ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
245 - ipfsi 0 p2p close -t /ip4/127.0.0.1/tcp/10101 &&
245 + ipfsi 0 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10101 /ipfs/$PEERID_1 &&
246 + echo "/x/p2p-test /ipfs/$PEERID_0 /ip4/127.0.0.1/tcp/10101" > expected &&
247 +
248 + ipfsi 0 p2p close -l /ip4/127.0.0.1/tcp/10101 &&
249 + ipfsi 0 p2p ls > actual &&
250 + test_cmp expected actual
251 +'
252 +
253 +check_test_ports
254 +
255 +test_expect_success "'ipfs p2p close' closes by listen addr" '
256 + ipfsi 0 p2p close -l /ipfs/$PEERID_0 &&
257 ipfsi 0 p2p ls > actual &&
258 test_must_be_empty actual
259 '