...
1
2
3
4 package eureka
5
6 import (
7 "os"
8 "testing"
9 "time"
10
11 "github.com/hudl/fargo"
12
13 "github.com/go-kit/log"
14 )
15
16
17
18
19
20
21
22
23
24
25 func TestIntegration(t *testing.T) {
26 eurekaAddr := os.Getenv("EUREKA_ADDR")
27 if eurekaAddr == "" {
28 t.Skip("EUREKA_ADDR is not set")
29 }
30
31 logger := log.NewLogfmtLogger(os.Stderr)
32 logger = log.With(logger, "ts", log.DefaultTimestamp)
33
34 var fargoConfig fargo.Config
35
36 fargoConfig.Eureka.ServiceUrls = []string{eurekaAddr}
37
38 fargoConfig.Eureka.PollIntervalSeconds = 1
39
40
41 fargoConnection := fargo.NewConnFromConfig(fargoConfig)
42 registrar1 := NewRegistrar(&fargoConnection, instanceTest1, log.With(logger, "component", "registrar1"))
43
44
45 registrar1.Register()
46 defer registrar1.Deregister()
47
48
49 instancer := NewInstancer(
50 &fargoConnection,
51 appNameTest,
52 log.With(logger, "component", "instancer"),
53 )
54 defer instancer.Stop()
55
56
57 waitForInstances := func(count int) {
58 for t := 0; t < 100; t++ {
59 state := instancer.state()
60 if len(state.Instances) == count {
61 return
62 }
63 time.Sleep(100 * time.Millisecond)
64 }
65 state := instancer.state()
66 if state.Err != nil {
67 t.Error(state.Err)
68 }
69 if want, have := 1, len(state.Instances); want != have {
70 t.Errorf("want %d, have %d", want, have)
71 }
72 }
73
74
75 waitForInstances(1)
76
77
78 registrar2 := NewRegistrar(&fargoConnection, instanceTest2, log.With(logger, "component", "registrar2"))
79 registrar2.Register()
80 defer registrar2.Deregister()
81
82
83
84 waitForInstances(2)
85
86
87 registrar2.Deregister()
88
89
90
91 waitForInstances(1)
92 }
93
View as plain text