(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestElect(t *testing.T) { |
| 77 | endpoints := []string{addr} |
| 78 | |
| 79 | testElectPath := util.RandString(32) |
| 80 | id0 := util.RandString(40) |
| 81 | node0, err := New(id0, &Config{ |
| 82 | Username: username, |
| 83 | Password: password, |
| 84 | DBName: dbName, |
| 85 | NotifyChannel: notifyChannel, |
| 86 | ElectPath: testElectPath, |
| 87 | Addrs: endpoints, |
| 88 | }) |
| 89 | require.NoError(t, err) |
| 90 | require.Eventuallyf(t, func() bool { |
| 91 | return node0.Leader() == node0.myID |
| 92 | }, 10*time.Second, 100*time.Millisecond, "node0 should be the leader") |
| 93 | |
| 94 | id1 := util.RandString(40) |
| 95 | node1, err := New(id1, &Config{ |
| 96 | Username: username, |
| 97 | Password: password, |
| 98 | DBName: dbName, |
| 99 | NotifyChannel: notifyChannel, |
| 100 | ElectPath: testElectPath, |
| 101 | Addrs: endpoints, |
| 102 | }) |
| 103 | require.NoError(t, err) |
| 104 | require.Eventuallyf(t, func() bool { |
| 105 | return node1.Leader() == node0.myID |
| 106 | }, 10*time.Second, 100*time.Millisecond, "node1's leader should be the node0") |
| 107 | |
| 108 | go func() { |
| 109 | for { |
| 110 | select { |
| 111 | case <-node0.LeaderChange(): |
| 112 | // do nothing |
| 113 | case <-node1.LeaderChange(): |
| 114 | // do nothing |
| 115 | } |
| 116 | } |
| 117 | }() |
| 118 | |
| 119 | require.NoError(t, node0.Close()) |
| 120 | |
| 121 | require.Eventuallyf(t, func() bool { |
| 122 | return node1.Leader() == node1.myID |
| 123 | }, 15*time.Second, 100*time.Millisecond, "node1 should be the leader") |
| 124 | } |
nothing calls this directly
no test coverage detected