-
Notifications
You must be signed in to change notification settings - Fork 666
grpc-js: Fix connectivity state change event sequencing #2421
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
Merged
murgatroid99
merged 1 commit into
grpc:@grpc/[email protected]
from
murgatroid99:grpc-js_waitForReady_fix
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright 2023 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import * as assert from 'assert'; | ||
import * as path from 'path'; | ||
|
||
import * as grpc from '../src'; | ||
import {sendUnaryData, Server, ServerCredentials, ServerUnaryCall, ServiceClientConstructor, ServiceError} from '../src'; | ||
|
||
import {loadProtoFile} from './common'; | ||
|
||
const protoFile = path.join(__dirname, 'fixtures', 'echo_service.proto'); | ||
const echoService = | ||
loadProtoFile(protoFile).EchoService as ServiceClientConstructor; | ||
|
||
describe.only('Global subchannel pool', () => { | ||
let server: Server; | ||
let serverPort: number; | ||
|
||
let client1: InstanceType<grpc.ServiceClientConstructor>; | ||
let client2: InstanceType<grpc.ServiceClientConstructor>; | ||
|
||
let promises: Promise<any>[]; | ||
|
||
before(done => { | ||
server = new Server(); | ||
server.addService(echoService.service, { | ||
echo(call: ServerUnaryCall<any, any>, callback: sendUnaryData<any>) { | ||
callback(null, call.request); | ||
}, | ||
}); | ||
|
||
server.bindAsync( | ||
'localhost:0', ServerCredentials.createInsecure(), (err, port) => { | ||
assert.ifError(err); | ||
serverPort = port; | ||
server.start(); | ||
done(); | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
promises = []; | ||
}) | ||
|
||
after(done => { | ||
server.tryShutdown(done); | ||
}); | ||
|
||
function callService(client: InstanceType<grpc.ServiceClientConstructor>) { | ||
return new Promise<void>((resolve) => { | ||
const request = {value: 'test value', value2: 3}; | ||
|
||
client.echo(request, (error: ServiceError, response: any) => { | ||
assert.ifError(error); | ||
assert.deepStrictEqual(response, request); | ||
resolve(); | ||
}); | ||
}) | ||
} | ||
|
||
function connect() { | ||
const grpcOptions = { | ||
'grpc.use_local_subchannel_pool': 0, | ||
} | ||
|
||
client1 = new echoService( | ||
`127.0.0.1:${serverPort}`, grpc.credentials.createInsecure(), | ||
grpcOptions); | ||
|
||
client2 = new echoService( | ||
`127.0.0.1:${serverPort}`, grpc.credentials.createInsecure(), | ||
grpcOptions); | ||
} | ||
|
||
/* This is a regression test for a bug where client1.close in the | ||
* waitForReady callback would cause the subchannel to transition to IDLE | ||
* even though client2 is also using it. */ | ||
it('Should handle client.close calls in waitForReady', | ||
done => { | ||
connect(); | ||
|
||
promises.push(new Promise<void>((resolve) => { | ||
client1.waitForReady(Date.now() + 50, (error) => { | ||
assert.ifError(error); | ||
client1.close(); | ||
resolve(); | ||
}); | ||
})) | ||
|
||
promises.push(new Promise<void>((resolve) => { | ||
client2.waitForReady(Date.now() + 50, (error) => { | ||
assert.ifError(error); | ||
resolve(); | ||
}); | ||
})) | ||
|
||
Promise.all(promises).then(() => {done()}); | ||
}) | ||
|
||
it('Call the service', done => { | ||
promises.push(callService(client2)); | ||
|
||
Promise.all(promises).then(() => { | ||
done(); | ||
}); | ||
}) | ||
|
||
it('Should complete the client lifecycle without error', done => { | ||
setTimeout(() => { | ||
client1.close(); | ||
client2.close(); | ||
done() | ||
}, 500); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@murgatroid99
What's the purpose of this call?
It looks like some debugging leftover. It doesn't make anything asynchronous, it just adds an empty function to be called by Event Loop after synchronous part of the code is executed.
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.
You're right. That was part of a change that I was trying out before I went in a different direction.