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

test: cross-version sync with @comapeo/core@2.0.1 #941

Merged
merged 5 commits into from
Oct 29, 2024
Merged

Conversation

EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented Oct 28, 2024

Depends on #856.

I recommend reviewing this with whitespace changes disabled.

This tests that we can connect and sync between the current version and @comapeo/core@2.0.1.

Notably, it required several changes to our test utilities to support the current MapeoManager and older ones. (One of these changes allowed us to remove a test-only method from MapeoManager.)

Our tests currenly connect `MapeoManager`s in two ways:

1. By starting peer discovery servers and connecting. This is similar to
   what the real app does.
2. By manually creating streams and connecting them in tests. This is
   less realistic.

This commit removes the second way because:

- it is less realistic
- it lets us remove some test-only code in the `src/` directory
- it will make an upcoming change easier

I also tried to fix a possible (test-only) race condition, which *could*
have been a reason for the less realistic option:

1. Start connecting peers by calling `connectPeers()`. This begins the
   process of starting peer discovery servers.
2. Disconnect them by calling the callback returned by `connectPeers()`.
3. The peer discovery servers start, and begin connecting. *This is bad*
   because we already wanted to disconnect!
This tests that we can connect and sync between the current version and
`@comapeo/core@2.0.1`.

Notably, it required several changes to our test utilities to support
the current `MapeoManager` and older ones. (One of these changes allowed
us to remove a test-only method from `MapeoManager`.)
Comment on lines -224 to -229
/**
* MapeoRPC instance, used for tests
*/
get [kRPC]() {
return this.#localPeers
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed.

managers.every((manager) => {
const unconnectedDeviceIds = new Set(deviceIds)
unconnectedDeviceIds.delete(manager.deviceId)
for (const peer of manager[kRPC].peers) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to do a small amount of work to stop calling a private method.

Base automatically changed from connect-peers-realistically-in-tests to main October 29, 2024 12:59
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

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

ok looks good. For maintainability, it could be helpful to change this later to be an option of createManager, e.g. createManager({ managerConstructor: MapeoManager2_0_1 }). However to do this, we need to have defaults for the migrations folders. Having it as a constructor option allows us to write tests as we develop to test specific changes between versions, without needing to keep adding test utils.

@EvanHahn
Copy link
Contributor Author

I'll do that the moment we start testing with another older version.

@EvanHahn EvanHahn merged commit 2db6be2 into main Oct 29, 2024
8 checks passed
@EvanHahn EvanHahn deleted the sync-with-2.0.1 branch October 29, 2024 14:57
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