Skip to content

Commit

Permalink
(revert!) Add logs to debug test in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Oct 11, 2024
1 parent 968d330 commit d767b48
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ ${ENDGROUP}`)
'--runInBand',
'--forceExit',
'--verbose',
'--silent',
// '--silent',
...(isTestJob
? ['--json', `--outputFile=${test.file}${RESULTS_EXT}`]
: []),
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cancel-request/pages/api/edge-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const config = {
let streamable: ReturnType<typeof Streamable> | undefined

export default async function handler(req: NextRequest): Promise<Response> {
console.log('handler', req.url)
if (req.nextUrl.searchParams.has('compile')) {
// The request just wants to trigger compilation.
return new Response(null, { status: 204 })
Expand All @@ -22,13 +23,15 @@ export default async function handler(req: NextRequest): Promise<Response> {
if (write) {
const s = (streamable = Streamable(+write))

console.log('aborted:', req.signal.aborted)
// The request was aborted before the response was returned.
if (req.signal.aborted) {
s.abort()
return new Response(null, { status: 204 })
}

req.signal.onabort = () => {
console.log('onabort')
s.abort()
}

Expand Down
4 changes: 4 additions & 0 deletions test/e2e/cancel-request/stream-cancel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ describe('streaming responses cancel inner stream after disconnect', () => {
function prime(url: string, noData?: boolean) {
return new Promise<void>((resolve, reject) => {
url = new URL(url, next.url).href
console.log('prime', url)

// There's a bug in node-fetch v2 where aborting the fetch will never abort
// the connection, because the body is a transformed stream that doesn't
// close the connection stream.
// https://github.com/node-fetch/node-fetch/pull/670
const req = get(url, async (res) => {
console.log('response')
while (true) {
const value = res.read(1)
console.log('received value:', value)
if (value) break
await sleep(5)
}

console.log('res.destroy()')
res.destroy()
resolve()
})
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cancel-request/streamable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function Streamable(write: number) {
finished: Promise.all([cleanedUp.promise, aborted.promise]).then(() => i),

abort() {
console.log('abort, startedConsuming:', startedConsuming)
aborted.resolve()

if (!startedConsuming) {
Expand All @@ -19,6 +20,7 @@ export function Streamable(write: number) {
},
stream: new ReadableStream({
async pull(controller) {
console.log('pull')
startedConsuming = true

if (i >= write) {
Expand All @@ -29,6 +31,7 @@ export function Streamable(write: number) {
controller.enqueue(encoder.encode(String(i++)))
},
cancel() {
console.log('cancel, startedConsuming:', startedConsuming)
cleanedUp.resolve()
},
}),
Expand Down

0 comments on commit d767b48

Please sign in to comment.