Files
elect/elect_test.go

33 lines
586 B
Go
Raw Normal View History

2023-06-01 06:43:35 -07:00
package elect_test
import (
"fmt"
"testing"
"time"
2023-06-04 10:31:26 -07:00
"github.com/dchest/uniuri"
2023-06-01 06:43:35 -07:00
"github.com/gopatchy/elect"
2023-06-04 10:31:26 -07:00
"github.com/gopatchy/proxy"
"github.com/samber/lo"
2023-06-01 06:43:35 -07:00
"github.com/stretchr/testify/require"
)
func TestSimple(t *testing.T) {
t.Parallel()
2023-06-04 10:31:26 -07:00
signingKey := uniuri.New()
2023-06-01 06:43:35 -07:00
2023-06-04 10:31:26 -07:00
ts := NewTestServer(t, signingKey)
defer ts.Stop()
2023-06-01 06:43:35 -07:00
2023-06-04 10:31:26 -07:00
p := lo.Must(proxy.NewProxy(t, ts.Addr()))
defer p.Close()
2023-06-01 06:43:35 -07:00
2023-06-04 10:31:26 -07:00
url := fmt.Sprintf("http://%s/", p.Addr())
2023-06-01 06:43:35 -07:00
2023-06-04 10:31:26 -07:00
v := elect.NewVoter(url, signingKey)
2023-06-01 06:43:35 -07:00
defer v.Stop()
2023-06-04 10:31:26 -07:00
require.Eventually(t, ts.Candidate.IsLeader, 15*time.Second, 100*time.Millisecond)
2023-06-01 06:43:35 -07:00
}