aboutsummaryrefslogtreecommitdiff
path: root/weed/cluster/cluster_test.go
diff options
context:
space:
mode:
author石昌林 <changlin.shi@ly.com>2022-06-28 10:06:04 +0800
committer石昌林 <changlin.shi@ly.com>2022-06-28 10:34:59 +0800
commite1b94eb6b96c89e97f1a431d2e0b53ad3db11ee4 (patch)
tree7e33749a683498444dd45800ad87807a1424cd36 /weed/cluster/cluster_test.go
parent4b1f48a399ac8e18154929b942d47e10c60a54d9 (diff)
downloadseaweedfs-e1b94eb6b96c89e97f1a431d2e0b53ad3db11ee4.tar.xz
seaweedfs-e1b94eb6b96c89e97f1a431d2e0b53ad3db11ee4.zip
fix `error: concurrent map writes` when add or remove cluster node
Diffstat (limited to 'weed/cluster/cluster_test.go')
-rw-r--r--weed/cluster/cluster_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/weed/cluster/cluster_test.go b/weed/cluster/cluster_test.go
index ccaccf6f7..1187642de 100644
--- a/weed/cluster/cluster_test.go
+++ b/weed/cluster/cluster_test.go
@@ -3,6 +3,8 @@ package cluster
import (
"github.com/chrislusf/seaweedfs/weed/pb"
"github.com/stretchr/testify/assert"
+ "strconv"
+ "sync"
"testing"
)
@@ -45,3 +47,35 @@ func TestClusterAddRemoveNodes(t *testing.T) {
c.RemoveClusterNode("", "filer", pb.ServerAddress("111:1"))
}
+
+func TestConcurrentAddRemoveNodes(t *testing.T) {
+ c := NewCluster()
+ var wg sync.WaitGroup
+ for i := 0; i < 50; i++ {
+ wg.Add(1)
+ go func(i int) {
+ defer wg.Done()
+ address := strconv.Itoa(i)
+ c.AddClusterNode("", "filer", pb.ServerAddress(address), "23.45")
+ }(i)
+ }
+ wg.Wait()
+
+ for i := 0; i < 50; i++ {
+ wg.Add(1)
+ go func(i int) {
+ defer wg.Done()
+ address := strconv.Itoa(i)
+ node := c.RemoveClusterNode("", "filer", pb.ServerAddress(address))
+
+ if len(node) == 0 {
+ t.Errorf("TestConcurrentAddRemoveNodes: node[%s] not found", address)
+ return
+ } else if node[0].ClusterNodeUpdate.Address != address {
+ t.Errorf("TestConcurrentAddRemoveNodes: expect:%s, actual:%s", address, node[0].ClusterNodeUpdate.Address)
+ return
+ }
+ }(i)
+ }
+ wg.Wait()
+}