Repository navigation
[pull] main from miniflux:main - #348
Merged
Merged
Conversation
Every integration tests in api_integration_test.go run sequentially against a live server and are network-bound, taking around one minutes on my machine. Each test is already isolated: it creates its own random-username user and operates through that user's own client, with feeds/categories/ entries scoped per user. The shared admin client is only used read-only or on error-path tests that create no durable state, and no test asserts 8000 global counts, so the suite is safe to parallelize. Add t.Parallel() to every test. No t.Setenv/Chdir or t.Run subtests are present, so nothing conflicts with parallel execution. It speeds things up from ~60s to ~7s on my machine. I ran the full testsuite a handful of times just to be sure™, but didn't get any flakiness.
TestRequestBuilder_TimeoutConfiguration dominated the whole test suite at ~2s. The handler slept a fixed 2s, and httptest.Server.Close() blocks until in-flight handlers finish, so the package always paid the full sleep even though the client timed out at 1s. Block the handler on <-r.Context().Done() instead: when the client times out and drops the connection, the request context is cancelled and the handler returns immediately, so Close() no longer waits. Shrink the timeout to 100ms as well.
Every integration talking to a JSON API hand-rolled the same dance: json.Marshal the payload, build an *http.Request, set the Content-Type and User-Agent headers, then run it through NewClientWithOptions. This is near-identical copy-paste, so any change done to how requests are done had to be repeated in each one. This commit introduces a small request builder in internal/http/client and route every integration through it: ``` client.NewRequestBuilder(endpoint). WithMethod(http.MethodPost). WithJSON(payload). WithHeaders(extraHeaders). Do() ``` Centralizing the logic also evens out disparities that had crept in between integrations: - private networks are now blocked everywhere, honoring INTEGRATION_ALLOW_PRIVATE_NETWORKS; notion previously did not block them; - request errors are wrapped consistently with %w instead of a mix of %v/%w; - the per-integration defaultClientTimeout constant is replaced by a single shared default in the client package; - the Content-Type and Miniflux User-Agent headers are always set. Reviewed-By: gudvinr
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )