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

Fix Reconnection Logic #168

Merged
merged 26 commits into from
Oct 31, 2024
Merged

Fix Reconnection Logic #168

merged 26 commits into from
Oct 31, 2024

Conversation

jdetter
Copy link
Collaborator

@jdetter jdetter commented Oct 12, 2024

Description of Changes

Describe what has been changed, any new features or bug fixes

  • switched our "already connected" logic to using a reference to a MonoBehaviour instead of just a bool. MonoBehaviours are typically destroyed when a scene reload happens and in this case we'll want to allow developers to spawn a new SpacetimeDBNetworkManager if the previous one has been destroyed.

API

This is not an API break.

  • This is an API breaking change to the SDK

If the API is breaking, please state below what will break

Requires SpacetimeDB PRs

List any PRs here that are required for this SDK change to work

Testsuite

SpacetimeDB branch name: master

Testing

Write instructions for a test that you performed for this PR

  • I have added in several new tests here, one of which is a reconnection test. Also, the reason why we couldn't have more than 1 test before this is that it was required for reconnections to be working in order to have multiple tests running in the testsuite. Now that we have fixed reconnections I have enabled all of the tests.

Testsuite passes

image

@jdetter
Copy link
Collaborator Author

jdetter commented Oct 12, 2024

This only fixes some surface level issues, there are some deeper problems here with how we handle client side indexes that will need to be fixed.

^ This has been fixed by Jeremie's SpacetimeDB PR

@jdetter jdetter mentioned this pull request Oct 12, 2024
@jdetter jdetter force-pushed the jdetter-fix-reconnection-logic branch 2 times, most recently from c764afb to 0bb78dd Compare October 16, 2024 03:52
@jdetter jdetter changed the base branch from staging to jdetter/unity-testsuite October 22, 2024 09:06
@jdetter jdetter force-pushed the jdetter-fix-reconnection-logic branch from 0bb78dd to 14cf1a3 Compare October 22, 2024 09:30
@jdetter jdetter force-pushed the jdetter/unity-testsuite branch from 5d47384 to 25a8c1b Compare October 22, 2024 09:53
@jdetter jdetter force-pushed the jdetter-fix-reconnection-logic branch from 14cf1a3 to 8c9c9e7 Compare October 22, 2024 09:59
public class SpacetimeDBNetworkManager : MonoBehaviour
{
private static bool _alreadyInitialized;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't exposed before to the users so this is not an API break

using SpacetimeDB;
using UnityEngine;

namespace SpacetimeDB
{
// This class is only used in Unity projects.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry for the whitespace changes here, this file wasn't properly formatted before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reminder that you can view the diff with whitespace turned off
image

@@ -15,7 +15,7 @@ public sealed class RemoteTables
{
public class CircleHandle : RemoteTableHandle<EventContext, Circle>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this file is automatically generated

@jdetter jdetter mentioned this pull request Oct 22, 2024
2 tasks
@jdetter jdetter marked this pull request as ready for review October 22, 2024 12:57
@jdetter jdetter requested review from RReverser, bfops and lcodes October 22, 2024 12:57
@jdetter jdetter force-pushed the jdetter/unity-testsuite branch from 746d728 to 547187e Compare October 22, 2024 13:07
@jdetter jdetter force-pushed the jdetter-fix-reconnection-logic branch from 602d07b to 9c25cf7 Compare October 22, 2024 13:12
private void ForEachConnection(Action<IDbConnection> action)
{
// TODO(jdetter): We're doing this for now because we can't break the API during a minor release but
// in the future we should just change ActiveConnections to be a list so that we can reverse-iterate
Copy link
Member

Choose a reason for hiding this comment

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

ActiveConnections is already not part of the public API though? Or do you mean some other API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought that ActiveConnections was referenced in the bindings somewhere and I was worried about creating an API break there, but I grep'd in the SpacetimeDB project for ActiveConnections and there's nothing there so maybe you're right. Thanks for the heads up 👍

Copy link
Member

Choose a reason for hiding this comment

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

It has internal visibility so bindings couldn't use it even if they wanted to.

@Centril Centril force-pushed the jdetter/unity-testsuite branch from a39e0a3 to 87fa4fc Compare October 30, 2024 12:05
@lcodes lcodes force-pushed the jdetter-fix-reconnection-logic branch 2 times, most recently from ed0fcdf to 3dcfbad Compare October 30, 2024 20:33
@jdetter jdetter mentioned this pull request Oct 30, 2024
3 tasks
Centril pushed a commit that referenced this pull request Oct 31, 2024
**Please do not rebase this PR**

## Description of Changes
*Describe what has been changed, any new features or bug fixes*

This is very similar to
#176
except it imports the circle game as a submodule instead of copying the
code over into this repo. This is the SpacetimeDBCircleGame PR that
we're dependent on right now:
clockworklabs/SpacetimeDBCircleGame#3

- This PR introduces a testsuite which runs in Unity. Right now it just
spawns in a circle, eats some food and verifies the decay logic is
working correctly. I've also written some reconnection tests but they
don't work because reconnections are currently broken. There are also
one-off tests but those don't work either because they also require
reconnections to be working.

Update: reconnections have been fixed via
#168.

I've used the built-in unity testsuite framework to achieve this, along
with the UnityCI tool from GameCI. The documentation for this docker
container can be found here:
https://game.ci/docs/github/getting-started/

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

Not breaking

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

None

## Testsuite

SpacetimeDB branch name: 0935b7346b825b8cbb9f36d9ed256136b73b5f0b

## Testing
*Write instructions for a test that you performed for this PR*

- [x] The testsuite is passing:
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/actions/runs/11604456943/job/32313229775

You can follow test instructions here to double check my work:
clockworklabs/SpacetimeDBCircleGame#3

## Follow-up Actions

- [ ] Rebase the reconnection logic PR onto this PR and re-enable the
reconnection tests

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
@lcodes lcodes changed the base branch from jdetter/unity-testsuite to staging October 31, 2024 17:53
@lcodes lcodes force-pushed the jdetter-fix-reconnection-logic branch from 3dcfbad to 56f82c3 Compare October 31, 2024 18:07
John Detter and others added 16 commits October 31, 2024 14:23
the future

Add testing section to PR description (#164)

v  Below is a render of what the new PR description looks like

*Describe what has been changed, any new features or bug fixes*

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

*List any PRs here that are required for this SDK change to work*

*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed

Working on a more ergonomic CI workflow

Workflow runs on staging

Small bug fix

Test again

speedup

Use public bindings

Use serial instead of license

Updated default branch to be master

Disable all but one test because we don't support reconnections right
now

Small update

Fixes

Testsuite uses local reference to SDK

Added comma

debugging

One more debug

Small changes

small sed fix

Small fix - newline character was messing up branch name

Added debug

Updated how branch name is populated

We'll give this a try to make the C# SDK happy

C# tests building!

Updated README

Small fix

Move unity-tests to unity-tests~

Use relative path reference

Use relative path reference

Small update to the workflow

Updated README for new functionality
causing errors.

Disconnected connection should be removed from active connections

Small fix that has to do with the active connections list being modified
during enumeration

Small fix

Another fix

Small simplification, should be working now

Small improvement to how OnDestroy works

Small fix

Compilation fix

:shrug-emoji:

Updated tests

NPM ignore file

Fix reconnection issues

Small compilation fix

Small fix

Fixes for reconnections

Reformat

Self review

Restored API - no API breaks here

Fix C# SDK Tests

Super small polish

Updated readme + publish/generate scripts

Move unity-tests to unity-tests~

Resolving conflicts

Fixing conflicts
@lcodes lcodes force-pushed the jdetter-fix-reconnection-logic branch from 44c95c7 to 41e0bd5 Compare October 31, 2024 18:23
@jdetter jdetter enabled auto-merge (squash) October 31, 2024 22:34
@jdetter jdetter merged commit 3581ed7 into staging Oct 31, 2024
3 of 4 checks passed
@jdetter jdetter deleted the jdetter-fix-reconnection-logic branch October 31, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants