Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette committed Aug 14, 2023
1 parent c504747 commit 07d55b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions http_comms/comms.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,11 @@ func NewHTTPCommunicator(
logger: logger,
clock: clock,
}

// Shuffle the list of URLs so that if a server goes down,
// clients will be distributed better accross
// the remaining servers.
rand.Seed(time.Now().UnixNano())
rand.Seed(utils.GetTime().Now().UnixNano())
rand.Shuffle(len(urls), func(i, j int) {
urls[i], urls[j] = urls[j], urls[i]
})
Expand Down
46 changes: 37 additions & 9 deletions http_comms/comms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ func (self *CommsTestSuite) TestAbort() {

func (self *CommsTestSuite) TestEnrollment() {
urls := []string{self.frontend1.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -266,9 +269,12 @@ func (self *CommsTestSuite) TestEnrollment() {

func (self *CommsTestSuite) TestServerError() {
urls := []string{self.frontend1.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -315,9 +321,12 @@ func (self *CommsTestSuite) TestServerError() {
// 500, Frontend2 is down too.
func (self *CommsTestSuite) TestMultiFrontends() {
urls := []string{self.frontend1.URL, self.frontend2.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -377,9 +386,12 @@ func (self *CommsTestSuite) TestMultiFrontends() {
// Client configured with two frontends. Both keep failing.
func (self *CommsTestSuite) TestMultiFrontendsAllIsBorked() {
urls := []string{self.frontend1.URL, self.frontend2.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -452,9 +464,12 @@ func (self *CommsTestSuite) TestMultiFrontendsAllIsBorked() {
// switching to FE2
func (self *CommsTestSuite) TestMultiFrontendsIntermittantFailure() {
urls := []string{self.frontend1.URL, self.frontend2.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -513,9 +528,12 @@ func (self *CommsTestSuite) TestMultiFrontendsIntermittantFailure() {
// fails we switch back to FE1.
func (self *CommsTestSuite) TestMultiFrontendsHeavyFailure() {
urls := []string{self.frontend1.URL, self.frontend2.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -588,9 +606,12 @@ func (self *CommsTestSuite) TestMultiFrontendsHeavyFailure() {
func (self *CommsTestSuite) TestMultiFrontendRedirect() {
// FE2 is not known to the client in advance.
urls := []string{self.frontend1.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -655,10 +676,14 @@ func (self *CommsTestSuite) TestMultiFrontendRedirect() {

// Check that redirects do not cause un-neccesary sleeps.
func (self *CommsTestSuite) TestMultiFrontendRedirectWithErrors() {
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

urls := []string{self.frontend1.URL}

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -751,9 +776,12 @@ func (self *CommsTestSuite) TestMultiFrontendRedirectWithErrors() {
// Frontends redirecting to each other.
func (self *CommsTestSuite) TestMultiRedirects() {
urls := []string{self.frontend1.URL}
mock_clock := utils.NewMockClock(time.Unix(100, 0))
cancel := utils.MockTime(mock_clock)
defer cancel()

clock := &FakeClock{
MockClock: utils.NewMockClock(time.Unix(100, 0)),
MockClock: mock_clock,
events: &self.frontend1.events}

ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 07d55b3

Please sign in to comment.