cluster_test.go 896 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cluster
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb"
  4. "strconv"
  5. "sync"
  6. "testing"
  7. )
  8. func TestConcurrentAddRemoveNodes(t *testing.T) {
  9. c := NewCluster()
  10. var wg sync.WaitGroup
  11. for i := 0; i < 50; i++ {
  12. wg.Add(1)
  13. go func(i int) {
  14. defer wg.Done()
  15. address := strconv.Itoa(i)
  16. c.AddClusterNode("", "filer", "", "", pb.ServerAddress(address), "23.45")
  17. }(i)
  18. }
  19. wg.Wait()
  20. for i := 0; i < 50; i++ {
  21. wg.Add(1)
  22. go func(i int) {
  23. defer wg.Done()
  24. address := strconv.Itoa(i)
  25. node := c.RemoveClusterNode("", "filer", pb.ServerAddress(address))
  26. if len(node) == 0 {
  27. t.Errorf("TestConcurrentAddRemoveNodes: node[%s] not found", address)
  28. return
  29. } else if node[0].ClusterNodeUpdate.Address != address {
  30. t.Errorf("TestConcurrentAddRemoveNodes: expect:%s, actual:%s", address, node[0].ClusterNodeUpdate.Address)
  31. return
  32. }
  33. }(i)
  34. }
  35. wg.Wait()
  36. }