Fix test suite under Rack 3 - #318
Merged
Merged
Conversation
Merging develop into master re-resolved Gemfile.lock and bumped rack 2.2.24 -> 3.2.7, since the Gemfile declared `gem 'rack'` unpinned. Rack 3.0 removed Rack::Server (extracted into the separate rackup gem, which is not in the bundle), and test/models/test_ontology_common.rb used it to stand up a throwaway HTTP server for ontology pull tests. That single removed constant produced 6 errors: one direct hit in test_download_ontology_file, four in TestOntology where pullLocation validation failed against a server that never started, and one in test_purl_creation as collateral -- test_case.rb sets Thread.abort_on_exception = true, so the dead server thread's NameError was re-raised inside an unrelated test. Changes: - Replace Rack::Server with WEBrick::HTTPServer in start_server. webrick is already a test dependency and works under both rack 2 and 3, so this merges back to develop without divergence. Also replaces the Thread.pass/sleep startup guesswork with a StartCallback + Queue#pop that blocks until the socket accepts, and exposes the server via thread[:webrick] so teardown shuts it down instead of leaking it. - Pin rack to ~> 3.2 so the major version is a decision, not an accident of lockfile re-resolution. The gemspec stays unpinned. - Bump rack-test ~> 0.6 (0.6.3, 2014) to ~> 2.1. It predates the Rack 3 SPEC. This required adding an explicit require of rack/builder to the test/rack tests, since 0.6.3 loaded all of rack while 2.x does not. - Lowercase response header keys in Serializer.response. Rack 3 requires lowercase keys, and Rack::Utils.set_cookie_header! already emits a lowercase set-cookie, so responses were carrying mixed-case keys. Full suite: 325 runs, 18025 assertions, 0 failures, 0 errors, 5 skips. Run count and skips unchanged; the 13 added assertions are the test_download_ontology_file assertions that previously never ran. Note: develop still locks rack 2.2.24. Everything here works under both, except the Gemfile pin. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #318 +/- ##
=======================================
Coverage 82.03% 82.03%
=======================================
Files 101 101
Lines 6853 6853
=======================================
Hits 5622 5622
Misses 1231 1231
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
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.
Problem
The unit test suite passes on
developbut fails with 6 errors onmaster.Merging
developintomasterre-resolvedGemfile.lockand bumped rack 2.2.24 → 3.2.7, because theGemfiledeclaredgem 'rack'with no version constraint:Gemfile.lockdevelop2.2.24master(59b1732e^)2.2.23master(before this PR)3.2.7Rack 3.0 removed
Rack::Server(extracted into the separaterackupgem, which is not in the bundle).test/models/test_ontology_common.rbused it to stand up a throwaway HTTP server serving"test file", which the ontology pull tests download from.One removed constant, six errors
TestOntologySubmission#test_download_ontology_filestart_serverraisesNameError: uninitialized constant Rack::ServerTestOntology#test_duplicate_contacts,#test_next_submission_id,#test_ontology_deletes_submissions,#test_ontology_acronym_uniquebefore_suitestarts the same dead server, so nothing listens on the port and goo rejects the save:pullLocation ... does not point to a valid fileTestOntology#test_purl_creationtest/test_case.rbsetsThread.abort_on_exception = true, so the dead server thread'sNameErroris re-raised in the main thread — it landed inside aNet::HTTPcall tolocalhost:9000(that'sGOO_PORT, the triplestore, not purl).enable_purlisfalse, so this test body never actually ran. It needed no fix of its own.Changes
Replace
Rack::ServerwithWEBrick::HTTPServerinstart_server.webrickis already a test-group dependency, and this works under both rack 2 and rack 3, so it merges back todevelopwithout divergence. Two incidental improvements:StartCallback+Queue#popreplaces the oldThread.pass/sleep 3startup guesswork and blocks until the socket actually accepts.TestOntology.before_suitehad no sleep at all — a latent flake.thread[:webrick]exposes the server so teardown canshutdownit;Thread.killalone left the listening socket open until GC.Pin
rackto~> 3.2so the major version is a deliberate choice rather than an accident of lockfile re-resolution. The gemspec stays unpinned, as a library's should.Bump
rack-testfrom~> 0.6(0.6.3, released 2014, predates the Rack 3 SPEC) to~> 2.1. This required adding an explicitrequire "rack/builder"to thetest/racktests — 0.6.3 loaded all of rack as a side effect, 2.x does not.Lowercase response header keys in
Serializer.response. Rack 3 requires lowercase keys (rack 2'sRack::Utils::HeaderHashused to normalize case and no longer exists).Rack::Utils.set_cookie_header!already emits a lowercaseset-cookie, so responses were carrying mixed-case keys and any downstreamheaders['content-type']lookup would silently miss.Rack 3 audit
Checked the rest of the codebase against the installed
rack-3.2.7.Rack::Request,Rack::Response#finish, andRack::Utils.parse_query/build_query/build_nested_query/parse_cookies/set_cookie_header!all still exist and behave correctly. Nothing references the removedRack::Utils::HeaderHash.Rack::Serverwas the only removed constant this repo touched.Testing
Full suite, before and after:
Same run count and same 5 skips, so nothing was silently dropped. The 13 added assertions are the
test_download_ontology_fileassertions that previously never executed becausestart_serverblew up first.Also verified:
rake test:rackpasses (guards the header-case and rack-test changes).test/models/test_ontology.rbrun 3× consecutively, 16/16 each time — confirms the startup race is gone.shutdowncalls land.test_purl_creationpasses without being touched, confirming it was collateral rather than a purl problem.Follow-up, not in this PR
developstill locks rack 2.2.24 and still hasgem 'rack'unpinned, so its next re-resolve can jump to rack 3 on its own and reintroduce this exact breakage there. Everything in this PR works under both rack 2 and 3 except theGemfilepin — worth pinningdevelopdeliberately to one major version.ontologies_apicontent negotiation.serializer.rbreadsenv['rack-accept.request'], injected by therack-acceptgem — not a dependency here, unmaintained, no Rack 3 release. This library degrades gracefully (falls back toenv["HTTP_ACCEPT"]), but the API app needs checking when it moves to rack 3.🤖 Generated with Claude Code