Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: don't emit task shutdown delay event if not waiting #16281

Merged
merged 3 commits into from Mar 3, 2023

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Mar 1, 2023

#14775 introduced a new task event when the task runner is waiting for the shutdown_delay, but some requests can be configured to ignore the shutdown_delay, in which case it can confusing to have this event, so emit one that notes the delay is being skipped instead.

No changelog or backports necessary since #14775 has not being released yet.

I just realized that I should've merged this for 1.5.0 🤦

Not big deal, but I added a changelog entry now.

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines 1112 to 1120
// Check that we only emit the expected events.
hasEvent := false
for _, ev := range tr.state.Events {
require.NotEqual(t, structs.TaskWaitingShuttingDownDelay, ev.Type)
if ev.Type == structs.TaskSkippingShutdownDelay {
hasEvent = true
}
}
require.True(t, hasEvent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but I think this kind of loop is what must.Contains was designed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't quite make that work. The best I was able to do was something like this:

want := &structs.TaskEvent{Type: structs.TaskSkippingShutdownDelay}
must.SliceContainsFunc(t, tr.state.Events, want, func(a, b *structs.TaskEvent) bool {
	return a.Type == b.Type
})

But SliceNotContainsFunc, which I would have to use to check for the absence of TaskWaitingShuttingDownDelay doesn't exist yet, so I left the initial implementation but replacing require with must.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SliceNotContainsFunc

probably should exist, created shoenig/test#110

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

I was thinking about the ergonomics of this use case, and I think it could be helpful to have something like these:

s := []string{"hit", "miss"}

must.SliceAtLeastOne(s, func(i string) bool {
  return i == "hit"
}) // success

must.SliceAll(s, func(i string) bool {
  return i == "hit"
}) // fail

must.SliceNone(s, func(i string) bool {
  return i == "none"
}) // success

Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.5.x backport to 1.5.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants