Skip to content

Commit

Permalink
Fix TestRemoteRelationWorkerError
Browse files Browse the repository at this point in the history
  • Loading branch information
hpidcock committed Jul 21, 2023
1 parent 355c341 commit c86e0d9
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions worker/firewaller/firewaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ func (s *InstanceModeSuite) TestConfigureModelFirewall(c *gc.C) {
}

func (s *InstanceModeSuite) setupRemoteRelationRequirerRoleConsumingSide(
c *gc.C, published chan bool, apiErr <-chan bool, ingressRequired *bool, clock clock.Clock,
c *gc.C, published chan bool, shouldErr func() bool, ingressRequired *bool, clock clock.Clock,
) (worker.Worker, *state.RelationUnit) {
// Set up the consuming model - create the local app.
wordpress := s.AddTestingApplication(c, "wordpress", s.AddTestingCharm(c, "wordpress"))
Expand Down Expand Up @@ -1049,7 +1049,7 @@ func (s *InstanceModeSuite) setupRemoteRelationRequirerRoleConsumingSide(
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{}},
}
if <-apiErr {
if shouldErr() {
return errors.New("fail")
}
if !*ingressRequired || len(argNetworks) > 0 {
Expand Down Expand Up @@ -1104,9 +1104,9 @@ func (s *InstanceModeSuite) setupRemoteRelationRequirerRoleConsumingSide(
func (s *InstanceModeSuite) TestRemoteRelationRequirerRoleConsumingSide(c *gc.C) {
published := make(chan bool)
ingressRequired := true
apiErr := make(chan bool, 2)
apiErr <- false
apiErr <- false
apiErr := func() bool {
return false
}
fw, ru := s.setupRemoteRelationRequirerRoleConsumingSide(c, published, apiErr, &ingressRequired, s.clock)
defer statetesting.AssertKillAndWait(c, fw)

Expand Down Expand Up @@ -1134,15 +1134,31 @@ func (s *InstanceModeSuite) TestRemoteRelationRequirerRoleConsumingSide(c *gc.C)
func (s *InstanceModeSuite) TestRemoteRelationWorkerError(c *gc.C) {
published := make(chan bool, 1)
ingressRequired := true
apiErr := make(chan bool)

apiCalled := make(chan struct{}, 1)
callCount := 0
apiErr := func() bool {
select {
case apiCalled <- struct{}{}:
case <-time.After(coretesting.ShortWait):
}
callCount += 1
return callCount == 1
}
fw, ru := s.setupRemoteRelationRequirerRoleConsumingSide(c, published, apiErr, &ingressRequired, s.clock)
defer statetesting.AssertKillAndWait(c, fw)

// Add a unit on the consuming app and have it enter the relation scope.
// This will trigger the firewaller to try and publish the changes.
err := ru.EnterScope(map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
apiErr <- true

select {
case <-apiCalled:
case <-time.After(coretesting.LongWait):
c.Fatal("time out waiting for api to be called")
}

// We should not have published any ingress events yet - no changed published.
select {
case <-time.After(coretesting.ShortWait):
Expand All @@ -1153,7 +1169,6 @@ func (s *InstanceModeSuite) TestRemoteRelationWorkerError(c *gc.C) {
s.clock.Advance(time.Minute)

// Give the worker time to restart and try again.
apiErr <- false
select {
case <-time.After(coretesting.LongWait):
c.Fatal("time out waiting for ingress change to be published on enter scope")
Expand Down

0 comments on commit c86e0d9

Please sign in to comment.