8 func TestRegistrar(t *testing.T) {
9 connection := &testConnection{
10 errHeartbeat: errTest,
13 registrar1 := NewRegistrar(connection, instanceTest1, loggerTest)
14 registrar2 := NewRegistrar(connection, instanceTest2, loggerTest)
17 registrar1.Deregister()
18 if want, have := 0, len(connection.instances); want != have {
19 t.Errorf("want %d, have %d", want, have)
24 if want, have := 1, len(connection.instances); want != have {
25 t.Errorf("want %d, have %d", want, have)
29 if want, have := 2, len(connection.instances); want != have {
30 t.Errorf("want %d, have %d", want, have)
34 registrar1.Deregister()
35 if want, have := 1, len(connection.instances); want != have {
36 t.Errorf("want %d, have %d", want, have)
39 // Already registered.
41 if want, have := 2, len(connection.instances); want != have {
42 t.Errorf("want %d, have %d", want, have)
45 if want, have := 2, len(connection.instances); want != have {
46 t.Errorf("want %d, have %d", want, have)
49 // Wait for a heartbeat failure.
50 time.Sleep(1010 * time.Millisecond)
51 if want, have := 2, len(connection.instances); want != have {
52 t.Errorf("want %d, have %d", want, have)
54 registrar1.Deregister()
55 if want, have := 1, len(connection.instances); want != have {
56 t.Errorf("want %d, have %d", want, have)
60 func TestBadRegister(t *testing.T) {
61 connection := &testConnection{
65 registrar := NewRegistrar(connection, instanceTest1, loggerTest)
67 if want, have := 0, len(connection.instances); want != have {
68 t.Errorf("want %d, have %d", want, have)
72 func TestBadDeregister(t *testing.T) {
73 connection := &testConnection{
74 errDeregister: errTest,
77 registrar := NewRegistrar(connection, instanceTest1, loggerTest)
79 if want, have := 1, len(connection.instances); want != have {
80 t.Errorf("want %d, have %d", want, have)
82 registrar.Deregister()
83 if want, have := 1, len(connection.instances); want != have {
84 t.Errorf("want %d, have %d", want, have)
88 func TestExpiredInstance(t *testing.T) {
89 connection := &testConnection{
90 errHeartbeat: errNotFound,
93 registrar := NewRegistrar(connection, instanceTest1, loggerTest)
96 // Wait for a heartbeat failure.
97 time.Sleep(1010 * time.Millisecond)
99 if want, have := 1, len(connection.instances); want != have {
100 t.Errorf("want %d, have %d", want, have)