aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Petrov <andrey.petrov@shazow.net>2018-06-08 00:49:07 +0800
committerAndrey Petrov <andrey.petrov@shazow.net>2018-06-22 00:22:47 +0800
commit193a402cc08e69f8c6b92106e8e81104d260d26c (patch)
tree86e4c9ef1809653c8c19cb6411ca07a128deff94
parentdcca66bce8ec79bcf0e06c32f57d0011f8d9fa93 (diff)
downloaddexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar.gz
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar.bz2
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar.lz
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar.xz
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.tar.zst
dexon-193a402cc08e69f8c6b92106e8e81104d260d26c.zip
p2p: Test for peer.rw.flags race conditions
-rw-r--r--p2p/server_test.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/p2p/server_test.go b/p2p/server_test.go
index 7eca46938..65897e018 100644
--- a/p2p/server_test.go
+++ b/p2p/server_test.go
@@ -177,18 +177,25 @@ func TestServerDial(t *testing.T) {
if peer := srv.Peers()[0]; peer.Info().Network.Trusted {
t.Errorf("peer is trusted prematurely: %v", peer)
}
- srv.AddTrustedPeer(node)
- if peer := srv.Peers()[0]; !peer.Info().Network.Trusted {
- t.Errorf("peer is not trusted after AddTrustedPeer: %v", peer)
- }
- if peer := srv.Peers()[0]; peer.Inbound() {
- t.Errorf("peer is marked inbound")
- }
- srv.RemoveTrustedPeer(node)
- if peer := srv.Peers()[0]; peer.Info().Network.Trusted {
- t.Errorf("peer is trusted after RemoveTrustedPeer: %v", peer)
- }
+ done := make(chan bool)
+ go func() {
+ srv.AddTrustedPeer(node)
+ if peer := srv.Peers()[0]; !peer.Info().Network.Trusted {
+ t.Errorf("peer is not trusted after AddTrustedPeer: %v", peer)
+ }
+ srv.RemoveTrustedPeer(node)
+ if peer := srv.Peers()[0]; peer.Info().Network.Trusted {
+ t.Errorf("peer is trusted after RemoveTrustedPeer: %v", peer)
+ }
+ done <- true
+ }()
+
+ // Trigger potential race conditions
+ peer = srv.Peers()[0]
+ _ = peer.Inbound()
+ _ = peer.Info()
+ <-done
case <-time.After(1 * time.Second):
t.Error("server did not launch peer within one second")
}