You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
  1. package lock_manager
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. "time"
  7. )
  8. func TestAddServer(t *testing.T) {
  9. r := NewLockRing(100 * time.Millisecond)
  10. r.AddServer("localhost:8080")
  11. assert.Equal(t, 1, len(r.snapshots))
  12. r.AddServer("localhost:8081")
  13. r.AddServer("localhost:8082")
  14. r.AddServer("localhost:8083")
  15. r.AddServer("localhost:8084")
  16. r.RemoveServer("localhost:8084")
  17. r.RemoveServer("localhost:8082")
  18. r.RemoveServer("localhost:8080")
  19. assert.Equal(t, 8, len(r.snapshots))
  20. time.Sleep(110 * time.Millisecond)
  21. assert.Equal(t, 2, len(r.snapshots))
  22. }
  23. func TestLockRing(t *testing.T) {
  24. r := NewLockRing(100 * time.Millisecond)
  25. r.SetSnapshot([]pb.ServerAddress{"localhost:8080", "localhost:8081"})
  26. assert.Equal(t, 1, len(r.snapshots))
  27. r.SetSnapshot([]pb.ServerAddress{"localhost:8080", "localhost:8081", "localhost:8082"})
  28. assert.Equal(t, 2, len(r.snapshots))
  29. time.Sleep(110 * time.Millisecond)
  30. r.SetSnapshot([]pb.ServerAddress{"localhost:8080", "localhost:8081", "localhost:8082", "localhost:8083"})
  31. assert.Equal(t, 3, len(r.snapshots))
  32. time.Sleep(110 * time.Millisecond)
  33. assert.Equal(t, 2, len(r.snapshots))
  34. r.SetSnapshot([]pb.ServerAddress{"localhost:8080", "localhost:8081", "localhost:8082", "localhost:8083", "localhost:8084"})
  35. assert.Equal(t, 3, len(r.snapshots))
  36. }