@google-cloud/agones-sdk 1.24.0 → 1.26.0-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/lib/sdk_pb.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2020 Google LLC All Rights Reserved.
1
+ // Copyright 2022 Google LLC All Rights Reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "version": "1.24.0"
29
+ "version": "1.26.0-rc"
30
30
  }
@@ -152,7 +152,7 @@ describe('AgonesSDK', () => {
152
152
 
153
153
  describe('health', () => {
154
154
  it('calls the server and passes calls to stream', async () => {
155
- let stream = jasmine.createSpyObj('stream', ['write']);
155
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
156
156
  spyOn(agonesSDK.client, 'health').and.callFake(() => {
157
157
  return stream;
158
158
  });
@@ -163,7 +163,7 @@ describe('AgonesSDK', () => {
163
163
  });
164
164
 
165
165
  it('uses the same stream for subsequent calls', async () => {
166
- let stream = jasmine.createSpyObj('stream', ['write']);
166
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
167
167
  spyOn(agonesSDK.client, 'health').and.callFake(() => {
168
168
  return stream;
169
169
  });
@@ -187,8 +187,55 @@ describe('AgonesSDK', () => {
187
187
  }
188
188
  });
189
189
 
190
+ it('calls the server and handles stream write error if callback provided', async () => {
191
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
192
+ stream.write.and.callFake((chunk, encoding, callback) => {
193
+ callback('error');
194
+ });
195
+ spyOn(agonesSDK.client, 'health').and.callFake(() => {
196
+ return stream;
197
+ });
198
+ try {
199
+ agonesSDK.health((error) => {
200
+ expect(error).toEqual('error');
201
+ });
202
+ } catch (error) {
203
+ fail();
204
+ }
205
+ });
206
+
207
+ it('calls the server and re throws stream write error if no callback', async () => {
208
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
209
+ stream.write.and.callFake((chunk, encoding, callback) => {
210
+ callback('error');
211
+ });
212
+ spyOn(agonesSDK.client, 'health').and.callFake(() => {
213
+ return stream;
214
+ });
215
+ try {
216
+ agonesSDK.health();
217
+ fail();
218
+ } catch (error) {
219
+ expect(agonesSDK.client.health).toHaveBeenCalled();
220
+ expect(error).toEqual('error');
221
+ }
222
+ });
223
+
224
+ it('does not call error callback if there was no stream error', async () => {
225
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
226
+ stream.write.and.callFake((chunk, encoding, callback) => {
227
+ callback();
228
+ });
229
+ spyOn(agonesSDK.client, 'health').and.callFake(() => {
230
+ return stream;
231
+ });
232
+ agonesSDK.health(() => {
233
+ fail();
234
+ });
235
+ });
236
+
190
237
  it('calls the server and handles stream completing', async () => {
191
- let stream = jasmine.createSpyObj('stream', ['write']);
238
+ let stream = jasmine.createSpyObj('stream', ['write', 'on']);
192
239
  spyOn(agonesSDK.client, 'health').and.callFake((callback) => {
193
240
  let result = new messages.Empty();
194
241
  callback(undefined, result);
@@ -358,7 +405,7 @@ describe('AgonesSDK', () => {
358
405
  expect(agonesSDK.client.close).toHaveBeenCalled();
359
406
  });
360
407
  it('ends the health stream if set', async () => {
361
- let stream = jasmine.createSpyObj('stream', ['end', 'write']);
408
+ let stream = jasmine.createSpyObj('stream', ['end', 'write', 'on']);
362
409
  spyOn(agonesSDK.client, 'health').and.callFake(() => {
363
410
  return stream;
364
411
  });
package/src/agonesSDK.js CHANGED
@@ -93,14 +93,25 @@ class AgonesSDK {
93
93
  });
94
94
  }
95
95
 
96
- health() {
96
+ health(errorCallback) {
97
97
  if (this.healthStream === undefined) {
98
98
  this.healthStream = this.client.health(() => {
99
99
  // Ignore error as this can't be caught
100
100
  });
101
+ this.healthStream.on('error', () => {
102
+ // ignore error, prevent from being uncaught
103
+ });
101
104
  }
102
105
  const request = new messages.Empty();
103
- this.healthStream.write(request);
106
+ this.healthStream.write(request, null, (error) => {
107
+ if (error) {
108
+ if (errorCallback) {
109
+ errorCallback(error);
110
+ return;
111
+ }
112
+ throw error;
113
+ }
114
+ });
104
115
  }
105
116
 
106
117
  async getGameServer() {