Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit dd61d35

Browse files
authored
fix: Fix and re-enable previously broken tests (#1075)
* Fix and re-enable previously broken tests
1 parent 842690f commit dd61d35

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/agent/debuglet.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export class Debuglet extends EventEmitter {
192192
private controller: Controller | null;
193193
private completedBreakpointMap: {[key: string]: boolean};
194194

195+
// The following four variables are used for the "isReady" functionality.
196+
195197
// breakpointFetchedTimestamp represents the last timestamp when
196198
// breakpointFetched was resolved, which means breakpoint update was
197199
// successful.
@@ -765,8 +767,8 @@ export class Debuglet extends EventEmitter {
765767
}
766768
).debuggee.id;
767769
// TODO: Handle the case when `result` is undefined.
768-
that.emit('registered', (result as {debuggee: Debuggee}).debuggee.id); // FIXME: Do we need this?
769-
that.debuggeeRegistered.resolve(); // FIXME: Do we need this?
770+
that.emit('registered', (result as {debuggee: Debuggee}).debuggee.id);
771+
that.debuggeeRegistered.resolve();
770772
if (!that.fetcherActive) {
771773
that.startListeningForBreakpoints_();
772774
}
@@ -788,16 +790,23 @@ export class Debuglet extends EventEmitter {
788790
err.name === 'RegistrationExpiredError'
789791
? 0
790792
: this.config.internal.registerDelayOnFetcherErrorSec;
793+
// The debuglet is no longer ready and the promises are stale.
794+
this.updatePromise();
791795
this.scheduleRegistration_(delay);
792796
}
793797

798+
this.breakpointFetchedTimestamp = Date.now();
799+
if (this.breakpointFetched) {
800+
this.breakpointFetched.resolve();
801+
this.breakpointFetched = null;
802+
}
794803
this.updateActiveBreakpoints_(breakpoints);
795804
}
796805
);
797806
}
798807

799808
/**
800-
* updatePromise_ is called when debuggee is expired. debuggeeRegistered
809+
* updatePromise is called when debuggee is expired. debuggeeRegistered
801810
* CachedPromise will be refreshed. Also, breakpointFetched CachedPromise will
802811
* be resolved so that uses (such as GCF users) will not hang forever to wait
803812
* non-fetchable breakpoints.

test/test-debuglet.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ describe('Debuglet', () => {
11691169
debuglet.start();
11701170
});
11711171

1172-
/*it('should have breakpoints fetched when promise is resolved', function (done) {
1173-
// FIXME: Broken.
1172+
it('should have breakpoints fetched when promise is resolved', function (done) {
11741173
this.timeout(2000);
11751174
const breakpoint: stackdriver.Breakpoint = {
11761175
id: 'test1',
@@ -1189,7 +1188,6 @@ describe('Debuglet', () => {
11891188
.post(REGISTER_PATH)
11901189
.reply(200, {debuggee: {id: DEBUGGEE_ID}})
11911190
.get(BPS_PATH + '?successOnTimeout=true')
1192-
.twice()
11931191
.reply(200, {breakpoints: [breakpoint]});
11941192
const debugPromise = debuglet.isReadyManager.isReady();
11951193
debuglet.once('registered', () => {
@@ -1212,7 +1210,6 @@ describe('Debuglet', () => {
12121210
});
12131211

12141212
it('should resolve breakpointFetched promise when registration expires', function (done) {
1215-
// FIXME: Broken.
12161213
this.timeout(2000);
12171214
const debug = new Debug(
12181215
{projectId: 'fake-project', credentials: fakeCredentials},
@@ -1237,7 +1234,7 @@ describe('Debuglet', () => {
12371234
});
12381235

12391236
debuglet.start();
1240-
});*/
1237+
});
12411238

12421239
it('should reject breakpoints with conditions when allowExpressions=false', function (done) {
12431240
this.timeout(2000);
@@ -1425,8 +1422,7 @@ describe('Debuglet', () => {
14251422
// The test expires a breakpoint and then has the api respond with
14261423
// the breakpoint listed as active. It validates that the breakpoint
14271424
// is only expired with the server once.
1428-
/*it('should not update expired breakpoints', function (done) {
1429-
// FIXME: Broken
1425+
it('should not update expired breakpoints', function (done) {
14301426
const debug = new Debug(
14311427
{projectId: 'fake-project', credentials: fakeCredentials},
14321428
packageInfo
@@ -1440,6 +1436,7 @@ describe('Debuglet', () => {
14401436
forceNewAgent_: true,
14411437
});
14421438
const debuglet = new Debuglet(debug, config);
1439+
let unexpectedUpdate = false;
14431440
const scope = nock(config.apiUrl)
14441441
.post(REGISTER_PATH)
14451442
.reply(200, {debuggee: {id: DEBUGGEE_ID}})
@@ -1459,15 +1456,20 @@ describe('Debuglet', () => {
14591456
.times(4)
14601457
.reply(200, {breakpoints: [bp]});
14611458

1459+
// Get ready to fail the test if any additional updates come through.
1460+
nock.emitter.on('no match', req => {
1461+
if (req.path.startsWith(BPS_PATH) && req.method === 'PUT') {
1462+
unexpectedUpdate = true;
1463+
}
1464+
});
1465+
14621466
debuglet.once('registered', (id: string) => {
14631467
assert.strictEqual(id, DEBUGGEE_ID);
14641468
setTimeout(() => {
14651469
assert.deepStrictEqual(debuglet.activeBreakpointMap.test, bp);
14661470
setTimeout(() => {
14671471
assert(!debuglet.activeBreakpointMap.test);
1468-
// Fetcher disables if we re-update since endpoint isn't mocked
1469-
// twice
1470-
assert(debuglet.fetcherActive);
1472+
assert(!unexpectedUpdate, 'unexpected update request');
14711473
debuglet.stop();
14721474
scope.done();
14731475
done();
@@ -1476,7 +1478,7 @@ describe('Debuglet', () => {
14761478
});
14771479

14781480
debuglet.start();
1479-
});*/
1481+
});
14801482
});
14811483

14821484
describe('map subtract', () => {

test/test-firebase-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MockReference {
5757
if (onComplete) {
5858
onComplete(null);
5959
}
60-
return new Promise<any>(resolve => resolve(null));
60+
return Promise.resolve();
6161
}
6262

6363
getOrAdd(key: string): MockReference {
@@ -101,7 +101,7 @@ class MockReference {
101101
if (creating && this.parentRef) {
102102
this.parentRef.childAdded(this.key, value);
103103
}
104-
return new Promise<any>(resolve => resolve(null));
104+
return Promise.resolve();
105105
}
106106

107107
on(

0 commit comments

Comments
 (0)