Example #1
0
func TestRemote(t *testing.T) {
	config := fmt.Sprintf(`{"Network": %q}`, expectedNetwork)
	sm := subnet.NewMockManager(1, config)

	addr := "127.0.0.1:9999"

	ctx, cancel := context.WithCancel(context.Background())
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		RunServer(ctx, sm, addr, "", "", "")
		wg.Done()
	}()

	doTestRemote(ctx, t, addr)

	cancel()
	wg.Wait()
}
Example #2
0
func newFixture(t *testing.T) *fixture {
	f := &fixture{}

	config := fmt.Sprintf(`{"Network": %q}`, expectedNetwork)
	f.registry = subnet.NewMockRegistry("", config, nil)
	sm := subnet.NewMockManager(f.registry)

	f.srvAddr = "127.0.0.1:9999"

	f.ctx, f.cancel = context.WithCancel(context.Background())
	f.wg.Add(1)
	go func() {
		RunServer(f.ctx, sm, f.srvAddr, "", "", "")
		f.wg.Done()
	}()

	var err error
	f.sm, err = NewRemoteManager(f.srvAddr, "", "", "")
	if err != nil {
		panic(fmt.Sprintf("Failed to create remote mananager: %v", err))
	}

	for i := 0; ; i++ {
		_, err := f.sm.GetNetworkConfig(f.ctx, "_")
		if err == nil {
			break
		}

		if isConnRefused(err) {
			if i == 100 {
				t.Fatalf("Out of connection retries")
			}

			fmt.Println("Connection refused, retrying...")
			time.Sleep(300 * time.Millisecond)
			continue
		}

		t.Fatalf("GetNetworkConfig failed: %v", err)
	}

	return f
}