Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-flake stoppable tests #7232

Merged
merged 2 commits into from Dec 8, 2022
Merged

De-flake stoppable tests #7232

merged 2 commits into from Dec 8, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Dec 7, 2022

We've had a lot of issues where stoppable tests are flaky because they depend on measuring the time that something takes and hoping it's relatively close to a particular timeout that's supposed to be "controlling" the observed behavior.

This PR refactors the internal Stoppable object so that instead of taking a millisecond timeout value, it takes a DOM-style AbortSignal. This object is only used by ApolloServerPluginDrainHttpServer; we move the setTimeout from inside Stoppable into that plugin, which now creates an AbortController polyfilled from node-abort-controller (like we already are in the usage reporting plugin; note that once we drop Node v14 support we can switch to the built-in implementation).

Now the Stoppable test can control the grace period directly via AbortSignals rather than indirectly based on timeouts. This lets us drop all of the time measurements from the test. There still are some delays but they are just of the form "wait some time and double-check that nothing happened": the worst case scenario here is that a test passes that should fail because the thing would have happened if you'd waited slightly longer, but there shouldn't be any spurious failures.

Fixes #6963.

@netlify
Copy link

netlify bot commented Dec 7, 2022

Deploy Preview for apollo-server-docs failed.

Name Link
🔨 Latest commit 8fcb208
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/6392302aed9f84000a5f4f37

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 7, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 44c4ec3:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration
Apollo Server Issue #6963

We've had a lot of issues where `stoppable` tests are flaky because they
depend on measuring the time that something takes and hoping it's
relatively close to a particular timeout that's supposed to be
"controlling" the observed behavior.

This PR refactors the internal Stoppable object so that instead of
taking a millisecond timeout value, it takes a DOM-style AbortSignal.
This object is only used by ApolloServerPluginDrainHttpServer; we move
the setTimeout from inside Stoppable into that plugin, which now creates
an AbortController polyfilled from `node-abort-controller` (like we
already are in the usage reporting plugin; note that once we drop Node
v14 support we can switch to the built-in implementation).

Now the Stoppable test can control the grace period directly via
AbortSignals rather than indirectly based on timeouts. This lets us drop
all of the time measurements from the test. There still are some delays
but they are just of the form "wait some time and double-check that
nothing happened": the worst case scenario here is that a test passes
that should fail because the thing would have happened if you'd waited
slightly longer, but there shouldn't be any spurious failures.

Fixes #6963.
@glasser glasser force-pushed the glasser/deflake-stoppable-tests branch from d82f40e to 44c4ec3 Compare December 7, 2022 22:59
….test.ts

Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
@glasser glasser merged commit 3a4823e into main Dec 8, 2022
@glasser glasser deleted the glasser/deflake-stoppable-tests branch December 8, 2022 19:06
glasser pushed a commit that referenced this pull request Dec 12, 2022
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/server-plugin-response-cache@4.1.0

### Minor Changes

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - If the cache you
provide to the `cache` option is created with
`PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`
(new in `@apollo/utils.keyvaluecache@2.1.0`), the `fqc:` prefix will not
be added to cache keys.

## @apollo/server@4.3.0

### Minor Changes

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - If the cache you
provide to the `persistedQueries.cache` option is created with
`PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`
(new in `@apollo/utils.keyvaluecache@2.1.0`), the `apq:` prefix will not
be added to cache keys. Providing such a cache to `new ApolloServer()`
throws an error.

### Patch Changes

- [#7232](#7232)
[`3a4823e0d`](3a4823e)
Thanks [@glasser](https://github.com/glasser)! - Refactor the
implementation of `ApolloServerPluginDrainHttpServer`'s grace period.
This is intended to be a no-op.

- [#7229](#7229)
[`d057e2ffc`](d057e2f)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`util` package. This change is intended to be a no-op.

- [#7228](#7228)
[`f97e55304`](f97e553)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`url` package. This change is intended to be a no-op.

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - For ease of upgrade
from the recommended configuration of Apollo Server v3.9+, you can now
pass `new ApolloServer({ cache: 'bounded' })`, which is equivalent to
not providing the `cache` option (as a bounded cache is now the default
in AS4).

## @apollo/server-integration-testsuite@4.3.0

### Patch Changes

- [#7228](#7228)
[`f97e55304`](f97e553)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`url` package. This change is intended to be a no-op.

- Updated dependencies
\[[`3a4823e0d`](3a4823e),
[`d057e2ffc`](d057e2f),
[`f97e55304`](f97e553),
[`d7e9b9759`](d7e9b97),
[`d7e9b9759`](d7e9b97)]:
    -   @apollo/server@4.3.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky stoppable tests
2 participants