mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Rewrite specs to not start local dev servers
They cause flakies when different tests start them in parallel, and also make the specs more complicated.
This commit is contained in:
parent
9598ed9d1c
commit
bda2d90969
6 changed files with 9 additions and 106 deletions
|
@ -3,44 +3,16 @@
|
|||
RSpec.describe "gemcutter's dependency API" do
|
||||
context "when Gemcutter API takes too long to respond" do
|
||||
before do
|
||||
require_rack_test
|
||||
|
||||
port = find_unused_port
|
||||
@server_uri = "http://127.0.0.1:#{port}"
|
||||
|
||||
require_relative "../../support/artifice/endpoint_timeout"
|
||||
require_relative "../../support/silent_logger"
|
||||
|
||||
require "rackup/server"
|
||||
|
||||
@t = Thread.new do
|
||||
server = Rackup::Server.start(app: EndpointTimeout,
|
||||
Host: "0.0.0.0",
|
||||
Port: port,
|
||||
server: "webrick",
|
||||
AccessLog: [],
|
||||
Logger: Spec::SilentLogger.new)
|
||||
server.start
|
||||
end
|
||||
@t.run
|
||||
|
||||
wait_for_server("127.0.0.1", port)
|
||||
bundle "config set timeout 1"
|
||||
end
|
||||
|
||||
after do
|
||||
Artifice.deactivate
|
||||
@t.kill
|
||||
@t.join
|
||||
end
|
||||
|
||||
it "times out and falls back on the modern index" do
|
||||
install_gemfile <<-G, artifice: nil, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
|
||||
source "#{@server_uri}"
|
||||
install_gemfile <<-G, artifice: "endpoint_timeout"
|
||||
source "https://gem.repo1"
|
||||
gem "myrack"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching source index from #{@server_uri}/")
|
||||
expect(out).to include("Fetching source index from https://gem.repo1/")
|
||||
expect(the_bundle).to include_gems "myrack 1.0.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,53 +2,23 @@
|
|||
|
||||
RSpec.describe "fetching dependencies with a mirrored source" do
|
||||
let(:mirror) { "https://server.example.org" }
|
||||
let(:original) { "http://127.0.0.1:#{@port}" }
|
||||
|
||||
before do
|
||||
setup_server
|
||||
bundle "config set --local mirror.#{mirror} #{original}"
|
||||
end
|
||||
build_repo2
|
||||
|
||||
after do
|
||||
Artifice.deactivate
|
||||
@t.kill
|
||||
@t.join
|
||||
end
|
||||
|
||||
it "sets the 'X-Gemfile-Source' and 'User-Agent' headers and bundles successfully" do
|
||||
gemfile <<-G
|
||||
source "#{mirror}"
|
||||
gem 'weakling'
|
||||
G
|
||||
|
||||
bundle :install, artifice: nil
|
||||
bundle "config set --local mirror.#{mirror} https://gem.repo2"
|
||||
end
|
||||
|
||||
it "sets the 'X-Gemfile-Source' and 'User-Agent' headers and bundles successfully" do
|
||||
bundle :install, artifice: "endpoint_mirror_source"
|
||||
|
||||
expect(out).to include("Installing weakling")
|
||||
expect(out).to include("Bundle complete")
|
||||
expect(the_bundle).to include_gems "weakling 0.0.3"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setup_server
|
||||
require_rack_test
|
||||
@port = find_unused_port
|
||||
@server_uri = "http://127.0.0.1:#{@port}"
|
||||
|
||||
require_relative "../../support/artifice/endpoint_mirror_source"
|
||||
require_relative "../../support/silent_logger"
|
||||
|
||||
require "rackup/server"
|
||||
|
||||
@t = Thread.new do
|
||||
Rackup::Server.start(app: EndpointMirrorSource,
|
||||
Host: "0.0.0.0",
|
||||
Port: @port,
|
||||
server: "webrick",
|
||||
AccessLog: [],
|
||||
Logger: Spec::SilentLogger.new)
|
||||
end.run
|
||||
|
||||
wait_for_server("127.0.0.1", @port)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -514,26 +514,6 @@ module Spec
|
|||
ENV["GEM_HOME"] = old_gem_home
|
||||
end
|
||||
|
||||
def wait_for_server(host, port, seconds = 15)
|
||||
tries = 0
|
||||
sleep 0.5
|
||||
TCPSocket.new(host, port)
|
||||
rescue StandardError => e
|
||||
raise(e) if tries > (seconds * 2)
|
||||
tries += 1
|
||||
retry
|
||||
end
|
||||
|
||||
def find_unused_port
|
||||
port = 21_453
|
||||
begin
|
||||
port += 1 while TCPSocket.new("127.0.0.1", port)
|
||||
rescue StandardError
|
||||
false
|
||||
end
|
||||
port
|
||||
end
|
||||
|
||||
def exit_status_for_signal(signal_number)
|
||||
# For details see: https://en.wikipedia.org/wiki/Exit_status#Shell_and_scripts
|
||||
128 + signal_number
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "webrick"
|
||||
module Spec
|
||||
class SilentLogger < WEBrick::BasicLog
|
||||
def initialize(log_file = nil, level = nil)
|
||||
super(log_file, level || FATAL)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,8 +3,6 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem "rack", "~> 3.1"
|
||||
gem "rackup", "~> 2.1"
|
||||
gem "webrick", "~> 1.9"
|
||||
gem "rack-test", "~> 2.1"
|
||||
gem "compact_index", "~> 0.15.0"
|
||||
gem "sinatra", "~> 4.1"
|
||||
|
|
|
@ -18,8 +18,6 @@ GEM
|
|||
rack (>= 3.0.0)
|
||||
rack-test (2.2.0)
|
||||
rack (>= 1.3)
|
||||
rackup (2.2.1)
|
||||
rack (>= 3)
|
||||
rake (13.3.0)
|
||||
rake-compiler-dock (1.9.1)
|
||||
rb_sys (0.9.111)
|
||||
|
@ -35,7 +33,6 @@ GEM
|
|||
rack-session (>= 2.0.0, < 3)
|
||||
tilt (~> 2.0)
|
||||
tilt (2.6.0)
|
||||
webrick (1.9.1)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
|
@ -51,12 +48,10 @@ DEPENDENCIES
|
|||
fiddle
|
||||
rack (~> 3.1)
|
||||
rack-test (~> 2.1)
|
||||
rackup (~> 2.1)
|
||||
rake (~> 13.1)
|
||||
rb_sys
|
||||
rubygems-generate_index (~> 1.1)
|
||||
sinatra (~> 4.1)
|
||||
webrick (~> 1.9)
|
||||
|
||||
CHECKSUMS
|
||||
base64 (0.2.0) sha256=0f25e9b21a02a0cc0cea8ef92b2041035d39350946e8789c562b2d1a3da01507
|
||||
|
@ -69,7 +64,6 @@ CHECKSUMS
|
|||
rack-protection (4.1.1) sha256=51a254a5d574a7f0ca4f0672025ce2a5ef7c8c3bd09c431349d683e825d7d16a
|
||||
rack-session (2.1.0) sha256=437c3916535b58ef71c816ce4a2dee0a01c8a52ae6077dc2b6cd19085760a290
|
||||
rack-test (2.2.0) sha256=005a36692c306ac0b4a9350355ee080fd09ddef1148a5f8b2ac636c720f5c463
|
||||
rackup (2.2.1) sha256=f737191fd5c5b348b7f0a4412a3b86383f88c43e13b8217b63d4c8d90b9e798d
|
||||
rake (13.3.0) sha256=96f5092d786ff412c62fde76f793cc0541bd84d2eb579caa529aa8a059934493
|
||||
rake-compiler-dock (1.9.1) sha256=e73720a29aba9c114728ce39cc0d8eef69ba61d88e7978c57bac171724cd4d53
|
||||
rb_sys (0.9.111) sha256=65822fd8d57c248cd893db0efe01bc6edc15fcbea3ba6666091e35430c1cbaf0
|
||||
|
@ -77,7 +71,6 @@ CHECKSUMS
|
|||
rubygems-generate_index (1.1.3) sha256=3571424322666598e9586a906485e1543b617f87644913eaf137d986a3393f5c
|
||||
sinatra (4.1.1) sha256=4e997b859aa1b5d2e624f85d5b0fd0f0b3abc0da44daa6cbdf10f7c0da9f4d00
|
||||
tilt (2.6.0) sha256=263d748466e0d83e510aa1a2e2281eff547937f0ef06be33d3632721e255f76b
|
||||
webrick (1.9.1) sha256=b42d3c94f166f3fb73d87e9b359def9b5836c426fc8beacf38f2184a21b2a989
|
||||
|
||||
BUNDLED WITH
|
||||
2.7.0.dev
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue