-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
statemgr: add a NewUnlockErrorFull state manager for tests #25823
Conversation
I've frequently needed to coerce Unlock() errors for tests and it's been awkward and fraught every time, so I decided to add a full state manger that returns *mostly* errors. I intend to use this in conjunction with the clistate.Locker interface, which first calls Lock() (to block if the mutex is in use) at the start of Unlock(), so Lock() rather awkwardly needed to succeed.
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me in isolation! 👍 I'm not familiar with tests that would use this, so I can't quite picture how it'd be used. If you have one to hand, could you point at a test where you'd use it?
states/statemgr/statemgr_fake.go
Outdated
fakeP Transient | ||
|
||
lockLock sync.Mutex | ||
locked bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any of the struct members other than t
being used in the methods below. Would it make sense to remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I don't think we need any of the struct members, since all the state functions return errors. I'll remove them all!
Absolutely @alisdair , I should have included this from the start. The community PR that pushed me over the edge is this one: #25729 The terraform/command/clistate/state.go Lines 132 to 138 in b5f4f9a
And here's the very simple test I have ready to add to that PR: func TestUnlock(t *testing.T) {
ui := new(cli.MockUi)
l := NewLocker(context.Background(), 0, ui, &colorstring.Colorize{Disable: true})
l.Lock(statemgr.NewUnlockErrorFull(nil, nil), "test-lock")
err := l.Unlock(nil)
if err == nil {
t.Error("expected unlock error")
}
} |
…#25823) * statemgr: add a NewUnlockErrorFull state manager for tests I've frequently needed to coerce Unlock() errors for tests and it's been awkward and fraught every time, so I decided to add a full state manger that returns *mostly* errors. I intend to use this in conjunction with the clistate.Locker interface, which first calls Lock() (to block if the mutex is in use) at the start of Unlock(), so Lock() rather awkwardly needed to succeed.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
I've frequently needed to coerce
Unlock()
errors for tests and it's beenawkward and fraught every time, so I decided to add a full state manger
that returns mostly errors. I intend to use this in conjunction with
the
clistate.Locker
interface, which first callsstatemgr.Lock()
(to block if themutex is in use) at the start of
clistate.Unlock()
, sostatemgr.Lock()
rather awkwardly needed to succeed.