2021-11-08 15:52:40 +08:00
|
|
|
package cluster
|
2021-11-04 15:54:38 +08:00
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
2022-06-28 10:06:04 +08:00
|
|
|
"strconv"
|
|
|
|
"sync"
|
2021-11-04 15:54:38 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-06-28 10:06:04 +08:00
|
|
|
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)
|
2022-07-03 15:29:25 +08:00
|
|
|
c.AddClusterNode("", "filer", "", "", pb.ServerAddress(address), "23.45")
|
2022-06-28 10:06:04 +08:00
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(i int) {
|
|
|
|
defer wg.Done()
|
|
|
|
address := strconv.Itoa(i)
|
2022-07-11 05:01:53 +08:00
|
|
|
node := c.RemoveClusterNode("", "filer", pb.ServerAddress(address))
|
2022-06-28 10:06:04 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|