FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: fix flaky tests by KhafraDev · Pull Request #1523 · node-fetch/node-fetch · GitHub

test: fix flaky tests - #1523

Merged
jimmywarting merged 1 commit into
node-fetch:mainfrom
KhafraDev:fix-possibly-flaky-test
Jul 12, 2022
Merged

test: fix flaky tests#1523
jimmywarting merged 1 commit into
node-fetch:mainfrom
KhafraDev:fix-possibly-flaky-test

Conversation

KhafraDev commented Mar 16, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

Purpose

By relying upon a 100ms delay before aborting, it is possible for the request to succeed before being canceled.

Since these 2 tests merely ensures that cancellation via AbortController works, adding a delay isn't needed regardless.

Changes

Removes delay between request and canceling.

Additional information

Undici runs node-fetch's test suite (more or less) and this test is flaky (https://github.com/nodejs/undici/runs/5153562802?check_suite_focus=true for example).

Example code with the issue fixed:

import fetch from 'node-fetch';
import { createServer } from 'http';
import { once } from 'events';

const server = createServer((req, res) => res.end());
server.listen(3000, () => console.log('done'));
await once(server, 'listening');

let i = 1;
while (i++) {
	try {
		const controller = new AbortController();

		const promise = fetch(`http://localhost:3000/`, {
			method: 'POST',
			signal: controller.signal,
			headers: {
				'Content-Type': 'application/json',
				body: '{"hello": "world"}'
			}
		});

		controller.abort()

		const test = await promise;
		console.log('did not fail', test);
		break;
	} catch {
		if (i % 1e3 === 0) {
			console.log('did not fail after ' + i + ' tries');
		}
	}
}

KhafraDev changed the title tests: fix flaky tests test: fix flaky tests Mar 16, 2022

LinusU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Neat 👍

jimmywarting merged commit 11b7033 into node-fetch:main Jul 12, 2022

Copy link
Copy Markdown

🎉 This PR is included in version 3.2.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL