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

Adds tests to cover ModuleContext.Close #407

Merged
merged 2 commits into from
Mar 24, 2022
Merged

Adds tests to cover ModuleContext.Close #407

merged 2 commits into from
Mar 24, 2022

Conversation

codefromthecrypt
Copy link
Contributor

This backfills tests that ModuleContext.Close ends up calling
Store.CloseModule and SysContext.Close.

This backfills tests that ModuleContext.Close ends up calling
`Store.CloseModule` and `SysContext.Close`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
@codefromthecrypt codefromthecrypt requested review from nullpo-head and mathetake and removed request for nullpo-head March 23, 2022 11:49

// We use side effects to determine if Close in fact called store.CloseModule (without repeating store_test.go).
// One side effect of store.CloseModule is that the moduleName can no longer be looked up. Verify our base case.
require.Equal(t, s.Module(moduleName), m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nullpo-head here's an example of using other tests to build higher level signals that something happened.

For example, through this and other tests, we know that Module.Close() ends up resulting in runtime.Module(moduleName) == nil (provided you check the base case). This can lead to simpler tests when we are trying to see if a function that calls close executed. e.g. try to lookup the module it was called from.

require.Empty(t, sys.openedFiles)

// Verify it was actually closed, by trying to close it again.
err = file.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

another side-effect you can use. Ex. if you can't easily reach the store or the runtime.. if you can open a file, you can check that it closed, by trying to close it again!

require.NoError(t, sys.Close())
})

// TODO: fs but never used (ex file == nil)
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 won't be addressing these TODOs in this PR. This is just to unlock the other one. I'll do it in #394

@codefromthecrypt codefromthecrypt merged commit 6f3867f into main Mar 24, 2022
@codefromthecrypt codefromthecrypt deleted the close-tests branch March 24, 2022 00:08
@codefromthecrypt
Copy link
Contributor Author

thanks for the look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants