Skip to content

Conversation

@maxdml
Copy link
Collaborator

@maxdml maxdml commented Sep 8, 2025

  • Add a test exercising the mocking of the DBOSContext and WorkflowHandle interfaces
  • We need a wrapper handle for the mock Path in RunWorkflow (it does return a new handle from the DBOSContext.RunWorkflow). This will only be used on the mocking path.

go.mod Outdated
gotest.tools/v3 v3.5.2 // indirect
)

replace github.com/dbos-inc/dbos-transact-golang/dbos/mocks => ./mocks
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only importers of this module are our tests and they should always get the mocks from the development directory.

Copy link
Member

Choose a reason for hiding this comment

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

What does this do? It looks sketchy.

Copy link
Member

Choose a reason for hiding this comment

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

I see, the mocks files are being committed as part of our core codebase--do we really need to do that?

@maxdml maxdml marked this pull request as ready for review September 8, 2025 21:16
return *new(R), err
}

// Wrapper handle -- useful for handling mocks in RunWorkflow
Copy link
Member

Choose a reason for hiding this comment

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

What does this do? Why do we need it? Do users need to worry about it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The situation we have with RunWorkflow, is that only the interface methods are mockable. If you want to mock RunWorkflow and have it return a mock handle, only the "inner" call with get a mock. Then, in the package level method, we use information from that handle to return a new typed handle. This new handle, not being the mock, makes testing impossible.

What this does -- users don't need to worry -- is to fall back on a "proxy" handler if the interface RunWorkflow does not return the "normal" handlers (direct or polling). The proxy just calls in whatever was returned by RunWorkflow. This allow a mock handle to be passed through.

Copy link
Member

@kraftp kraftp Sep 9, 2025

Choose a reason for hiding this comment

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

Can't we just return a polling handle (passing in the mocked context) instead of this new thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Returning a new polling handle would be returning a new object that is not the mock returned by DBOSContext.RunWorkflow. We need a way to pass through the mock while respecting the function signature (return a generic WorkflowHandle[R] interface). Unfortunately we cannot just "cast" the mock (SomeMockType[any]) to WorkflowHandle[R]: any and R are different type. This proxy type:

  • Let us pass through the mock
  • Let us returned a typed mock

@maxdml maxdml merged commit 0afae2e into main Sep 9, 2025
2 checks passed
@maxdml maxdml deleted the test-mocks branch September 9, 2025 17:41
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.

3 participants