Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brought etcdv3 registrar only test to its own run #724

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions sd/etcdv3/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ func runIntegration(settings integrationSettings, client Client, service Service
registrar.Register()
t.Log("Registered")

// Deregister our instance. (so we test registrar only scenario)
registrar.Deregister()
t.Log("Deregistered")

// Re-Register our instance.
registrar.Register()
t.Log("Registered")

// Retrieve entries from etcd manually.
entries, err = client.GetEntries(settings.key)
if err != nil {
Expand Down Expand Up @@ -172,6 +164,50 @@ func TestIntegrationTTL(t *testing.T) {
runIntegration(settings, client, service, t)
}

func TestIntegrationRegistrarOnly(t *testing.T) {
settings := testIntegrationSettings(t)
client, err := NewClient(context.Background(), []string{settings.addr}, ClientOptions{
DialTimeout: 2 * time.Second,
DialKeepAlive: 2 * time.Second,
})
if err != nil {
t.Fatalf("NewClient(%q): %v", settings.addr, err)
}

service := Service{
Key: settings.key,
Value: settings.value,
TTL: NewTTLOption(time.Second*3, time.Second*10),
}
defer client.Deregister(service)

// Verify test data is initially empty.
entries, err := client.GetEntries(settings.key)
if err != nil {
t.Fatalf("GetEntries(%q): expected no error, got one: %v", settings.key, err)
}
if len(entries) > 0 {
t.Fatalf("GetEntries(%q): expected no instance entries, got %d", settings.key, len(entries))
}
t.Logf("GetEntries(%q): %v (OK)", settings.key, entries)

// Instantiate a new Registrar, passing in test data.
registrar := NewRegistrar(
client,
service,
log.With(log.NewLogfmtLogger(os.Stderr), "component", "registrar"),
)

// Register our instance.
registrar.Register()
t.Log("Registered")

// Deregister our instance. (so we test registrar only scenario)
registrar.Deregister()
t.Log("Deregistered")

}

func within(d time.Duration, f func() bool) bool {
deadline := time.Now().Add(d)
for time.Now().Before(deadline) {
Expand Down