Skip to content

Commit 266af4c

Browse files
committed
Add pick_first tests
1 parent 3ff8b67 commit 266af4c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/grpc-js/test/test-pick-first.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,54 @@ describe('pick_first load balancing policy', () => {
125125
subchannels[0].transitionToState(ConnectivityState.READY);
126126
});
127127
});
128+
it('Should report READY when a subchannel other than the first connects', done => {
129+
const channelControlHelper = createChildChannelControlHelper(
130+
baseChannelControlHelper,
131+
{
132+
updateState: updateStateCallBackForExpectedStateSequence(
133+
[ConnectivityState.CONNECTING, ConnectivityState.READY],
134+
done
135+
),
136+
}
137+
);
138+
const pickFirst = new PickFirstLoadBalancer(channelControlHelper);
139+
pickFirst.updateAddressList(
140+
[
141+
{ addresses: [{ host: 'localhost', port: 1 }] },
142+
{ addresses: [{ host: 'localhost', port: 2 }] },
143+
],
144+
config
145+
);
146+
process.nextTick(() => {
147+
subchannels[1].transitionToState(ConnectivityState.READY);
148+
});
149+
});
150+
it('Should report READY when a subchannel other than the first in the same endpoint connects', done => {
151+
const channelControlHelper = createChildChannelControlHelper(
152+
baseChannelControlHelper,
153+
{
154+
updateState: updateStateCallBackForExpectedStateSequence(
155+
[ConnectivityState.CONNECTING, ConnectivityState.READY],
156+
done
157+
),
158+
}
159+
);
160+
const pickFirst = new PickFirstLoadBalancer(channelControlHelper);
161+
pickFirst.updateAddressList(
162+
[
163+
{
164+
addresses: [
165+
{ host: 'localhost', port: 1 },
166+
{ host: 'localhost', port: 2 },
167+
],
168+
},
169+
],
170+
config
171+
);
172+
process.nextTick(() => {
173+
subchannels[1].transitionToState(ConnectivityState.READY);
174+
});
175+
});
128176
it('Should report READY when updated with a subchannel that is already READY', done => {
129177
const channelControlHelper = createChildChannelControlHelper(
130178
baseChannelControlHelper,

0 commit comments

Comments
 (0)