-
Notifications
You must be signed in to change notification settings - Fork 6
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
Client uses ReadStream and WriteStream #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
vi, | ||
onTestFinished, | ||
} from 'vitest'; | ||
import { iterNext } from '../util/testHelpers'; | ||
import { getIteratorFromStream, iterNext } from '../util/testHelpers'; | ||
import { | ||
SubscribableServiceSchema, | ||
TestServiceSchema, | ||
|
@@ -182,25 +182,27 @@ describe.each(testMatrix())( | |
clientTransport.eventDispatcher.numberOfListeners('message'); | ||
|
||
// start procedure | ||
const [input, output, close] = await client.test.echo.stream(); | ||
input.push({ msg: '1', ignore: false, end: undefined }); | ||
input.push({ msg: '2', ignore: false, end: true }); | ||
const [inputWriter, outputReader, close] = | ||
await client.test.echo.stream(); | ||
inputWriter.write({ msg: '1', ignore: false, end: undefined }); | ||
inputWriter.write({ msg: '2', ignore: false, end: true }); | ||
|
||
const result1 = await iterNext(output); | ||
const outputIterator = getIteratorFromStream(outputReader); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also when to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's just a helper, we can either remove |
||
const result1 = await iterNext(outputIterator); | ||
assert(result1.ok); | ||
expect(result1.payload).toStrictEqual({ response: '1' }); | ||
|
||
// ensure we only have one stream despite pushing multiple messages. | ||
await waitFor(() => expect(server.streams.size).toEqual(1)); | ||
input.end(); | ||
inputWriter.close(); | ||
// ensure we no longer have any streams since the input was closed. | ||
await waitFor(() => expect(server.streams.size).toEqual(0)); | ||
|
||
const result2 = await iterNext(output); | ||
const result2 = await iterNext(outputIterator); | ||
assert(result2.ok); | ||
expect(result2.payload).toStrictEqual({ response: '2' }); | ||
|
||
const result3 = await output.next(); | ||
const result3 = await outputIterator.next(); | ||
assert(result3.done); | ||
|
||
close(); | ||
|
@@ -252,18 +254,20 @@ describe.each(testMatrix())( | |
clientTransport.eventDispatcher.numberOfListeners('message'); | ||
|
||
// start procedure | ||
const [subscription, close] = await client.subscribable.value.subscribe( | ||
const [outputReader, close] = await client.subscribable.value.subscribe( | ||
{}, | ||
); | ||
let result = await iterNext(subscription); | ||
const outputIterator = getIteratorFromStream(outputReader); | ||
let result = await iterNext(outputIterator); | ||
assert(result.ok); | ||
expect(result.payload).toStrictEqual({ result: 0 }); | ||
const add1 = await client.subscribable.add.rpc({ n: 1 }); | ||
assert(add1.ok); | ||
result = await iterNext(subscription); | ||
result = await iterNext(outputIterator); | ||
assert(result.ok); | ||
|
||
close(); | ||
server; | ||
// end procedure | ||
|
||
// number of message handlers shouldn't increase after subscription ends | ||
|
@@ -313,11 +317,11 @@ describe.each(testMatrix())( | |
clientTransport.eventDispatcher.numberOfListeners('message'); | ||
|
||
// start procedure | ||
const [addStream, addResult] = | ||
const [inputWriter, addResult] = | ||
await client.uploadable.addMultiple.upload(); | ||
addStream.push({ n: 1 }); | ||
addStream.push({ n: 2 }); | ||
addStream.end(); | ||
inputWriter.write({ n: 1 }); | ||
inputWriter.write({ n: 2 }); | ||
inputWriter.close(); | ||
|
||
const result = await addResult; | ||
assert(result.ok); | ||
|
@@ -364,10 +368,11 @@ describe.each(testMatrix())( | |
}); | ||
|
||
// start a stream | ||
const [input, output] = await client.test.echo.stream(); | ||
input.push({ msg: '1', ignore: false }); | ||
const [inputWriter, outputReader] = await client.test.echo.stream(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like you naming these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🫡 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to update type annotations to have those names, but maybe we can do that in a follow up since we reference |
||
inputWriter.write({ msg: '1', ignore: false }); | ||
|
||
const result1 = await iterNext(output); | ||
const outputIterator = getIteratorFromStream(outputReader); | ||
const result1 = await iterNext(outputIterator); | ||
assert(result1.ok); | ||
expect(result1.payload).toStrictEqual({ response: '1' }); | ||
|
||
|
@@ -386,8 +391,8 @@ describe.each(testMatrix())( | |
await waitFor(() => expect(serverTransport.connections.size).toEqual(1)); | ||
|
||
// push on the old stream and make sure its not sent | ||
input.push({ msg: '2', ignore: false }); | ||
const result2 = await iterNext(output); | ||
expect(() => inputWriter.write({ msg: '2', ignore: false })).toThrow(); | ||
const result2 = await iterNext(outputIterator); | ||
assert(!result2.ok); | ||
}); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does a bare
await outputReader().next();
not work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, you need to grab the iterator