Skip to content

Commit

Permalink
fix: remove @google-cloud/common retries for CreateProfile and Update…
Browse files Browse the repository at this point in the history
…Profile requests (#555)
  • Loading branch information
nolanmar511 authored Oct 17, 2019
1 parent 437bd29 commit 09ef74d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ts/src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export class Profiler extends ServiceObject {
uri: '/profiles',
body: reqBody,
json: true,
maxRetries: 0,

// Default timeout for for a request is 1 minute, but request to create
// profile is designed to hang until it is time to collect a profile
Expand Down Expand Up @@ -490,6 +491,7 @@ export class Profiler extends ServiceObject {
uri: this.baseApiUrl + '/' + prof.name,
body: prof,
json: true,
maxRetries: 0,
};

try {
Expand Down
48 changes: 48 additions & 0 deletions ts/test/test-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,29 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
await profiler.profileAndUpload(requestProf);
});
it('should not retry on non-200 status codes', async () => {
const requestProf = {
name: 'projects/12345678901/test-projectId',
duration: '10s',
profileType: 'WALL',
labels: {instance: 'test-instance'},
};
nockOauth2();
const apiMock = nock(FULL_API)
.patch('/' + requestProf.name)
.once()
.reply(500)
.patch('/' + requestProf.name)
.once()
.reply(200);
const profiler = new Profiler(testConfig);
await profiler.profileAndUpload(requestProf);
assert.strictEqual(
apiMock.isDone(),
false,
'call to upload profile should not be retried'
);
});
it('should send request to upload profile to default API without error.', async () => {
const requestProf = {
name: 'projects/12345678901/test-projectId',
Expand Down Expand Up @@ -520,6 +543,31 @@ describe('Profiler', () => {
);
}
});
it('should not retry on non-200 status codes', async () => {
const response = {
name: 'projects/12345678901/test-projectId',
profileType: 'HEAP',
deployment: {
labels: {version: 'test-version', language: 'nodejs'},
projectId: 'test-projectId',
target: 'test-service',
},
labels: {version: testConfig.serviceContext.version},
};
nockOauth2();
nock(FULL_API)
.post('/projects/' + testConfig.projectId + '/profiles')
.once()
.reply(503, {})
.post('/projects/' + testConfig.projectId + '/profiles')
.once()
.reply(200, response);
const profiler = new Profiler(testConfig);
try {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (_) {}
});
it(
'should not have instance and zone in request body when instance and' +
' zone undefined',
Expand Down

0 comments on commit 09ef74d

Please sign in to comment.