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

refactor(blobstorage): tests converted to typescript #3742

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

iainsproat
Copy link
Contributor

Description & motivation

Typescripting more of the things.

Changes:

  • converts remaining modules/blobstorage tests to typescript.
  • uses a random user, as a small start to ensuring tests are not polluting and can be run in parallel (they can't be, currently).
  • requires that the owning user be provided as a parameter to the createStreamForTest function. This reduces surprising side-effects (in the previous case, the global user being used as the owner).
  • adds a comment to a helper method with, possibly surprising, side-effects.

To-do before merge:

Screenshots:

Validation of changes:

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

@iainsproat iainsproat marked this pull request as ready for review December 30, 2024 10:16
@iainsproat iainsproat requested a review from fabis94 January 2, 2025 09:51
*/
export async function createTestStream(
streamObj: BasicTestStream,
export async function createTestStream( //FIXME this function has side-effects, and amends the object in-place
Copy link
Contributor

Choose a reason for hiding this comment

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

@iainsproat The side-effects are definitely intentional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If/when we start running tests in parallel, the side-effects have a higher risk of test pollution if we're not super careful.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, this aspect of the function is a part of its core responsibilities, its pretty important to have it cause manually having to import id-generating functions, having to remember the correct lengths & formats of ids is a PITA that this aspect of the helper resolves. in fact, this was one of the main reasons for me even creating these. it would be a serious impact to DX if we were to remove it.

its not immediately obvious to me how these helpers would cause issues in parallel tests, but if any pop up we can deal with them then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The helper is fine, but it should ideally treat input as immutable. I'd expect it to return a deep clone plus the id as its output.

const createStreamForTest = async () => {
const stream = {
const createStreamForTest = async (streamOwner: BasicTestUser) => {
const stream: Partial<BasicTestStream> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it always the same user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes it explicit which user is being used for the test. I'd like to get to the point where we can run more tests in parallel, or at least shuffle the order, and making test object dependencies clear is going to be helpful for avoiding test pollution.
So yes, it's always the same user - at least for now.

@iainsproat iainsproat requested a review from fabis94 January 7, 2025 09:42
@iainsproat iainsproat merged commit c252339 into main Jan 7, 2025
26 of 28 checks passed
@iainsproat iainsproat deleted the iain/modules-blobstorage-tests-typescript branch January 7, 2025 10:19
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.

2 participants