Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: add more RPC client tests #408

Merged
merged 11 commits into from
Nov 22, 2022
Merged

feat: add more RPC client tests #408

merged 11 commits into from
Nov 22, 2022

Conversation

kratico
Copy link
Contributor

@kratico kratico commented Nov 16, 2022

Resolves #139

Description

Add error test cases for RPC client, proxyProvider, smoldotProvider and fix a few related bugs

const createMockClient = () => {
let listener: C.rpc.ProviderListener<Error, Error>
const providerMockFactory: Provider = (_discoveryValue, clientListener) => {
listener = clientListener
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is very coupled to how the rpc.Client calls the provider factory.
I'm open to more elegant suggestions to extract the client listener so we can emit testing messages/errors

Comment on lines +105 to +110
this.pendingSubscriptions[message.id] = (maybeError) => {
listenerBound(maybeError)
if (maybeError instanceof Error) {
stop()
}
}
Copy link
Contributor Author

@kratico kratico Nov 16, 2022

Choose a reason for hiding this comment

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

bug fix, subscriptions should stop on errors

this.call(message)
.then((maybeError) => {
if (maybeError instanceof Error) {
if (maybeError instanceof Error || maybeError.error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bug fix, if the subscription creation is not successful it should stop the subscription

@@ -47,7 +47,7 @@ export class Client<
const pendingCall = this.pendingCalls[id]!
pendingCall.resolve(e)
delete this.pendingCalls[id]
this.pendingSubscriptions[id]!(e)
this.pendingSubscriptions[id]?.(e)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bug fix, on error there may not be pendingSubscriptions for the given message id

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very important fix, as these errors were not getting caught, and thus crashed the process, including on the codegen server.

@kratico kratico marked this pull request as ready for review November 16, 2022 17:01
const { cleanUp, listeners, inner } = connection(url, listener)
let conn
try {
conn = connection(url, listener)
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 the connection was not created in .send, this call will attempt to create it again.
And if it fails to create the connection it will throw.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point... we bake in the assumption that the connection connection will resolve to an open connection. How might we want to adjust connection to resolve to an error in the case of an out-of-flow release?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copying comment from below

I believe that it would be better to just do

conn = connections.get(url)

Then, we need to decide what release should do if there is no connection.
One option could be that if there isn't anything to release, then do nothing.
Thoughts?

Copy link
Contributor

@harrysolovay harrysolovay left a comment

Choose a reason for hiding this comment

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

Added some thoughts –– want to pair on this next week?

rpc/client.test.ts Outdated Show resolved Hide resolved
rpc/provider/proxy.test.ts Outdated Show resolved Hide resolved
rpc/provider/proxy.test.ts Outdated Show resolved Hide resolved
const { cleanUp, listeners, inner } = connection(url, listener)
let conn
try {
conn = connection(url, listener)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point... we bake in the assumption that the connection connection will resolve to an open connection. How might we want to adjust connection to resolve to an error in the case of an out-of-flow release?

stopped.resolve()
})
// @ts-ignore make JSON.stringify to throw
provider.send(1n)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

try {
conn = await connection(props, listener)
} catch (_error) {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Although an error would likely mean that the connection is dead / "released", this––for some reason––seems not ideal. What're your thoughts on this?

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 believe that it would be better to just do

conn = connections.get(props)

Then, we need to decide what release should do if there is no connection.
One option could be that if there isn't anything to release, then do nothing.
Thoughts?

@kratico kratico requested a review from harrysolovay November 22, 2022 12:40
@kratico kratico merged commit 3b80c20 into main Nov 22, 2022
@kratico kratico deleted the feat/rpc-tests branch November 22, 2022 17:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tests for RPC clients
3 participants