-
Notifications
You must be signed in to change notification settings - Fork 0
fix(check): probe the Redis at REDIS_URL, not a pinned 127.0.0.1:6379 #538
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'minitest/autorun' | ||
| require 'open3' | ||
| require 'socket' | ||
| require 'tmpdir' | ||
|
|
||
| # bin/check's Redis guard must look where the suite will connect: REDIS_URL, | ||
| # which lib/wurk and test_helper already read, falling back to the default. | ||
| # A box whose Redis is not on 127.0.0.1:6379 (the developerz.ai fleet moves its | ||
| # sidecar off the well-known port so a repo's own store can bind it) must not | ||
| # be refused for a server the suite was never going to use. | ||
| # | ||
| # Drives the real script in `fast` mode with a stub `bundle` on PATH, so every | ||
| # stage past the guard is a no-op and the exit code is the guard's verdict. | ||
| class BinCheckRedisUrlTest < Minitest::Test | ||
| parallelize_me! | ||
|
|
||
| CHECK = File.expand_path('../../bin/check', __dir__) | ||
|
|
||
| def run_check(redis_url) | ||
| Dir.mktmpdir do |dir| | ||
| stub = File.join(dir, 'bundle') | ||
| File.write(stub, "#!/usr/bin/env bash\nexit 0\n") | ||
| File.chmod(0o755, stub) | ||
| env = { 'PATH' => "#{dir}:#{ENV.fetch('PATH')}", 'REDIS_URL' => redis_url } | ||
| Open3.capture3(env, CHECK, 'fast') | ||
| end | ||
| end | ||
|
|
||
| def closed_port | ||
| server = TCPServer.new('127.0.0.1', 0) | ||
| port = server.addr[1] | ||
| server.close | ||
| port | ||
| end | ||
|
|
||
| def test_refuses_when_the_redis_url_server_is_down_and_names_it | ||
| port = closed_port | ||
| _out, err, status = run_check("redis://127.0.0.1:#{port}/0") | ||
|
|
||
| assert_equal 75, status.exitstatus, err | ||
| assert_includes err, "127.0.0.1:#{port}" | ||
| end | ||
|
|
||
| # The unset-REDIS_URL fallback must be the suite's own default, byte for byte: a | ||
| # guard that probes `127.0.0.1` while RedisPool connects to `localhost` can pass | ||
| # or refuse over a server the suite never uses. Read, not run — the real 6379 | ||
| # on the box would otherwise decide the answer. | ||
| def test_the_unset_fallback_is_the_suites_own_default | ||
| suite_default = File.read(File.expand_path('../../lib/wurk/redis_pool.rb', __dir__))[ | ||
| /DEFAULT_URL\s*=\s*ENV\.fetch\('REDIS_URL', '([^']+)'\)/, 1 | ||
| ] | ||
|
|
||
| refute_nil suite_default, 'RedisPool::DEFAULT_URL must still read REDIS_URL with a literal fallback' | ||
| %w[bin/check bin/test-ecosystem].each do |script| | ||
| fallback = File.read(File.expand_path("../../#{script}", __dir__))[/\$\{REDIS_URL:-([^}]+)\}/, 1] | ||
|
|
||
| assert_equal suite_default, fallback, "#{script} must fall back to the suite's own default" | ||
| end | ||
| end | ||
|
|
||
| def test_runs_the_gate_when_the_redis_url_server_answers | ||
| server = TCPServer.new('127.0.0.1', 0) | ||
| begin | ||
| _out, err, status = run_check("redis://127.0.0.1:#{server.addr[1]}/3") | ||
|
|
||
| assert_equal 0, status.exitstatus, err | ||
| ensure | ||
| server.close | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.