Skip to content

Commit 5e8f5fa

Browse files
authored
Merge pull request #1905 from murgatroid99/grpc-js-xds_interop_improvements
grpc-js-xds: fix use of splice in interop test code
2 parents 255618e + 1ae04af commit 5e8f5fa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/grpc-js-xds/interop/xds-interop-client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ class CallStatsTracker {
130130

131131
private subscribers: CallSubscriber[] = [];
132132

133+
private removeSubscriber(subscriber: CallSubscriber) {
134+
const index = this.subscribers.indexOf(subscriber);
135+
if (index >= 0) {
136+
this.subscribers.splice(index, 1);
137+
}
138+
}
139+
133140
getCallStats(callCount: number, timeoutSec: number): Promise<LoadBalancerStatsResponse> {
134141
return new Promise((resolve, reject) => {
135142
let finished = false;
@@ -142,7 +149,7 @@ class CallStatsTracker {
142149
setTimeout(() => {
143150
if (!finished) {
144151
finished = true;
145-
this.subscribers.splice(this.subscribers.indexOf(subscriber), 1);
152+
this.removeSubscriber(subscriber);
146153
resolve(subscriber.getFinalStats());
147154
}
148155
}, timeoutSec * 1000)
@@ -155,7 +162,7 @@ class CallStatsTracker {
155162
for (const subscriber of callSubscribers) {
156163
subscriber.addCallStarted();
157164
if (!subscriber.needsMoreCalls()) {
158-
this.subscribers.splice(this.subscribers.indexOf(subscriber), 1);
165+
this.removeSubscriber(subscriber);
159166
}
160167
}
161168
return {

0 commit comments

Comments
 (0)