Skip to content

Commit 1ad1a9c

Browse files
committed
debug
1 parent df48298 commit 1ad1a9c

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

packages/cloudflare/test/request.test.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,24 @@ describe('withSentry', () => {
9191
});
9292

9393
test('flush must be called when all waitUntil are done', async () => {
94-
const flushSpy = vi.spyOn(SentryCore.Client.prototype, 'flush').mockImplementation(async function (this: any) {
95-
const callNum = flushSpy.mock.calls.length;
96-
console.log(`[FLUSH #${callNum}] Client: ${this?.constructor?.name || 'unknown'}`);
97-
const stack = new Error().stack?.split('\n').slice(2, 7).join('\n ');
94+
let flushCallCount = 0;
95+
const originalFlush = SentryCore.Client.prototype.flush;
96+
97+
const flushSpy = vi.spyOn(SentryCore.Client.prototype, 'flush').mockImplementation(async function (
98+
this: any,
99+
timeout?: number,
100+
) {
101+
flushCallCount++;
102+
console.log(`[FLUSH #${flushCallCount}] Client: ${this?.constructor?.name || 'unknown'}, timeout: ${timeout}`);
103+
const stack = new Error().stack?.split('\n').slice(2, 10).join('\n ');
98104
console.log(` Stack:\n ${stack}`);
99-
return true;
105+
console.log(` this._flushLock:`, this._flushLock ? 'exists' : 'undefined');
106+
console.log(
107+
` Recursion check: flushCallCount=${flushCallCount}, spy.calls.length=${flushSpy.mock.calls.length}`,
108+
);
109+
110+
// Important: Return a resolved promise to avoid triggering parent flush logic
111+
return Promise.resolve(true);
100112
});
101113
flushSpy.mockClear(); // Explicitly clear before test
102114

@@ -105,13 +117,32 @@ describe('withSentry', () => {
105117
vi.useRealTimers();
106118
flushSpy.mockRestore();
107119
});
120+
let pendingCount = 0;
108121
const waits: Promise<unknown>[] = [];
109122
const waitUntil = vi.fn(promise => {
110123
const callNum = waitUntil.mock.calls.length;
111-
console.log(`[WAITUNTIL #${callNum}]`);
124+
pendingCount++;
125+
console.log(
126+
`[WAITUNTIL #${callNum}] Pending: ${pendingCount}, Promise type: ${promise?.constructor?.name || 'unknown'}`,
127+
);
112128
const stack = new Error().stack?.split('\n').slice(2, 5).join('\n ');
113129
console.log(` Stack:\n ${stack}`);
114-
waits.push(promise);
130+
131+
// Wrap the promise to log when it resolves
132+
const wrappedPromise = promise.then(
133+
val => {
134+
pendingCount--;
135+
console.log(`[WAITUNTIL #${callNum} RESOLVED] Pending now: ${pendingCount}`);
136+
return val;
137+
},
138+
err => {
139+
pendingCount--;
140+
console.log(`[WAITUNTIL #${callNum} REJECTED] Pending now: ${pendingCount}`, err);
141+
throw err;
142+
},
143+
);
144+
145+
waits.push(wrappedPromise);
115146
});
116147

117148
const context = {

0 commit comments

Comments
 (0)