package hha

import (
	"context"
	"testing"
	"time"
)

func TestHttpHighAvailability_ServeHTTP(t *testing.T) {
	addr := "http://192.168.0.10:8001"
	path := "/alive"
	serverList := []string{
		"http://192.168.0.10:8001",
		"http://192.168.0.10:8002",
	}
	ha := New(addr, path, serverList)
	go func() {
		for {
			time.Sleep(1 * time.Second)
			t.Log(addr, ha.Alive)
		}
	}()
	if err := ha.Start(context.Background()); err != nil {
		t.Error(err)
	}
}

func TestHttpHighAvailability_Start(t *testing.T) {
	addr := "http://192.168.0.10:8002"
	path := "/alive"
	serverList := []string{
		"http://192.168.0.10:8001",
		"http://192.168.0.10:8002",
	}
	ha := New(addr, path, serverList)
	go func() {
		for {
			time.Sleep(1 * time.Second)
			t.Log(addr, ha.Alive)
		}
	}()
	if err := ha.Start(context.Background()); err != nil {
		t.Fatal(err)
	}
}
