Repository: hashicorp/nomad
File: client/heartbeatstop_test.go (Go)

Code before:
	}

	// an alloc with a longer lease
	alloc2 := alloc1.Copy()
	alloc2.ID = uuid.Generate()
	alloc2.Job.TaskGroups[0].Disconnect.StopOnClientAfter = pointer.Of(2 * time.Second)

	// an alloc with no disconnect config
	alloc3 := alloc1.Copy()
	alloc3.ID = uuid.Generate()
	alloc3.Job.TaskGroups[0].Disconnect = nil

	destroyers[alloc1.ID] = &mockAllocRunnerDestroyer{}
	destroyers[alloc2.ID] = &mockAllocRunnerDestroyer{}
	destroyers[alloc3.ID] = &mockAllocRunnerDestroyer{}

	go stopper.watch()
	stopper.allocHook(alloc1)
	stopper.allocHook(alloc2)
	stopper.allocHook(alloc3)

	must.Wait(t, wait.InitialSuccess(
		wait.Timeout(time.Second),
		wait.ErrorFunc(func() error {
			if destroyers[alloc1.ID].checkCalls() != 1 {
				return fmt.Errorf("first alloc was not destroyed as expected")
			}
			if destroyers[alloc2.ID].checkCalls() != 0 {
				return fmt.Errorf("second alloc was unexpectedly destroyed")
			}
			if destroyers[alloc3.ID].checkCalls() != 0 {
				return fmt.Errorf("third alloc should never be destroyed")
			}
			return nil
		})))

	// send a heartbeat and make sure nothing changes
	stopper.setLastOk(time.Now())

	must.Wait(t, wait.ContinualSuccess(
		wait.Timeout(time.Second),
		wait.ErrorFunc(func() error {
			if destroyers[alloc1.ID].checkCalls() != 1 {
				return fmt.Errorf("first alloc should no longer be tracked")
			}
			if destroyers[alloc2.ID].checkCalls() != 0 {
				return fmt.Errorf("second alloc was unexpectedly destroyed")
			}
			if destroyers[alloc3.ID].checkCalls() != 0 {
				return fmt.Errorf("third alloc should never be destroyed")
			}

Review comment (suggestion):
I know something in the past has linted `fmt.Errorf`s without any `%`s in em. I suppose there's no active check for that?  I think it would want all these to be

```suggestion
				return errors.New("first alloc was not destroyed as expected")
```

Code after:
	}

	// an alloc with a longer lease
	alloc2 := alloc1.Copy()
	alloc2.ID = uuid.Generate()
	alloc2.Job.TaskGroups[0].Disconnect.StopOnClientAfter = pointer.Of(500 * time.Millisecond)

	// an alloc with no disconnect config
	alloc3 := alloc1.Copy()
	alloc3.ID = uuid.Generate()
	alloc3.Job.TaskGroups[0].Disconnect = nil

	destroyers[alloc1.ID] = &mockAllocRunnerDestroyer{}
	destroyers[alloc2.ID] = &mockAllocRunnerDestroyer{}
	destroyers[alloc3.ID] = &mockAllocRunnerDestroyer{}

	go stopper.watch()
	stopper.allocHook(alloc1)
	stopper.allocHook(alloc2)
	stopper.allocHook(alloc3)

	must.Wait(t, wait.InitialSuccess(
		wait.Timeout(time.Second),
		wait.Gap(10*time.Millisecond),
		wait.ErrorFunc(func() error {
			if destroyers[alloc1.ID].checkCalls() != 1 {
				return errors.New("first alloc was not destroyed as expected")
			}
			if destroyers[alloc2.ID].checkCalls() != 0 {
				return errors.New("second alloc was unexpectedly destroyed")
			}
			if destroyers[alloc3.ID].checkCalls() != 0 {
				return errors.New("third alloc should never be destroyed")
			}
			return nil
		})))

	// send a heartbeat and make sure nothing changes
	stopper.setLastOk(time.Now())

	must.Wait(t, wait.ContinualSuccess(
		wait.Timeout(200*time.Millisecond),
		wait.Gap(10*time.Millisecond),
		wait.ErrorFunc(func() error {
			if destroyers[alloc1.ID].checkCalls() != 1 {
				return errors.New("first alloc should no longer be tracked")
			}
			if destroyers[alloc2.ID].checkCalls() != 0 {
				return errors.New("second alloc was unexpectedly destroyed")
			}
			if destroyers[alloc3.ID].checkCalls() != 0 {