mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Use Time.stub :now
to avoid a random failure
Essentially this reverts 45464bfcbdf9f9cfb440950bc57a27d237627a17. The commit removed a mock of Time.now, which caused a random failure. http://rubyci.s3.amazonaws.com/ubuntu1804/ruby-master/log/20210512T123004Z.fail.html.gz ``` 1) Failure: TestGemPackageTarWriter#test_add_file_signer [/home/chkbuild/chkbuild/tmp/build/20210512T123004Z/ruby/test/rubygems/test_gem_package_tar_writer.rb:117]: Field mtime of the tar header differs.. <"14046746312\u0000"> expected but was <"14046746311\x00">. ``` Object#stub is defined at f1af59fe02ef2cc58f13e2742e4cc6cf8c2a1a20, so now `Time.stub :now` works. https://github.com/rubygems/rubygems/commit/85f60a9ed0
This commit is contained in:
parent
9225352bf1
commit
9484f9ebdf
1 changed files with 109 additions and 85 deletions
|
@ -27,43 +27,52 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
end
|
||||
|
||||
def test_add_file
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file 'x', 0644 do |f|
|
||||
f.write 'a' * 10
|
||||
end
|
||||
|
||||
assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
|
||||
@io.string[0, 512])
|
||||
end
|
||||
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
|
||||
assert_equal 1024, @io.pos
|
||||
end
|
||||
|
||||
def test_add_file_source_date_epoch
|
||||
ENV["SOURCE_DATE_EPOCH"] = "123456789"
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.mkdir 'foo', 0644
|
||||
|
||||
assert_headers_equal tar_dir_header('foo', '', 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc),
|
||||
@io.string[0, 512]
|
||||
end
|
||||
end
|
||||
|
||||
def test_add_symlink
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_symlink 'x', 'y', 0644
|
||||
|
||||
assert_headers_equal(tar_symlink_header('x', '', 0644, Time.now, 'y'),
|
||||
@io.string[0, 512])
|
||||
end
|
||||
assert_equal 512, @io.pos
|
||||
end
|
||||
|
||||
def test_add_symlink_source_date_epoch
|
||||
ENV["SOURCE_DATE_EPOCH"] = "123456789"
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_symlink 'x', 'y', 0644
|
||||
|
||||
assert_headers_equal(tar_symlink_header('x', '', 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc, 'y'),
|
||||
@io.string[0, 512])
|
||||
end
|
||||
end
|
||||
|
||||
def test_add_file_digest
|
||||
digest_algorithms = Digest::SHA1.new, Digest::SHA512.new
|
||||
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
|
||||
io.write 'a' * 10
|
||||
end
|
||||
|
@ -78,7 +87,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
|
||||
assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
|
||||
@io.string[0, 512])
|
||||
|
||||
end
|
||||
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
|
||||
assert_equal 1024, @io.pos
|
||||
end
|
||||
|
@ -86,6 +95,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
def test_add_file_digest_multiple
|
||||
digest_algorithms = [Digest::SHA1.new, Digest::SHA512.new]
|
||||
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
|
||||
io.write 'a' * 10
|
||||
end
|
||||
|
@ -100,7 +110,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
|
||||
assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
|
||||
@io.string[0, 512])
|
||||
|
||||
end
|
||||
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
|
||||
assert_equal 1024, @io.pos
|
||||
end
|
||||
|
@ -110,6 +120,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
|
||||
signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT]
|
||||
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file_signed 'x', 0644, signer do |io|
|
||||
io.write 'a' * 10
|
||||
end
|
||||
|
@ -132,22 +143,26 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
|
||||
assert_equal 2048, @io.pos
|
||||
end
|
||||
end
|
||||
|
||||
def test_add_file_signer_empty
|
||||
signer = Gem::Security::Signer.new nil, nil
|
||||
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file_signed 'x', 0644, signer do |io|
|
||||
io.write 'a' * 10
|
||||
end
|
||||
|
||||
assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
|
||||
@io.string[0, 512])
|
||||
end
|
||||
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
|
||||
|
||||
assert_equal 1024, @io.pos
|
||||
end
|
||||
|
||||
def test_add_file_simple
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file_simple 'x', 0644, 10 do |io|
|
||||
io.write "a" * 10
|
||||
end
|
||||
|
@ -158,9 +173,11 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
|
||||
assert_equal 1024, @io.pos
|
||||
end
|
||||
end
|
||||
|
||||
def test_add_file_simple_source_date_epoch
|
||||
ENV["SOURCE_DATE_EPOCH"] = "123456789"
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file_simple 'x', 0644, 10 do |io|
|
||||
io.write "a" * 10
|
||||
end
|
||||
|
@ -168,12 +185,15 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc),
|
||||
@io.string[0, 512])
|
||||
end
|
||||
end
|
||||
|
||||
def test_add_file_simple_padding
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.add_file_simple 'x', 0, 100
|
||||
|
||||
assert_headers_equal tar_file_header('x', '', 0, 100, Time.now),
|
||||
@io.string[0, 512]
|
||||
end
|
||||
|
||||
assert_equal "\0" * 512, @io.string[512, 512]
|
||||
end
|
||||
|
@ -226,6 +246,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
end
|
||||
|
||||
def test_mkdir
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.mkdir 'foo', 0644
|
||||
|
||||
assert_headers_equal tar_dir_header('foo', '', 0644, Time.now),
|
||||
|
@ -233,14 +254,17 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
|
|||
|
||||
assert_equal 512, @io.pos
|
||||
end
|
||||
end
|
||||
|
||||
def test_mkdir_source_date_epoch
|
||||
ENV["SOURCE_DATE_EPOCH"] = "123456789"
|
||||
Time.stub :now, Time.at(1458518157) do
|
||||
@tar_writer.mkdir 'foo', 0644
|
||||
|
||||
assert_headers_equal tar_dir_header('foo', '', 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc),
|
||||
@io.string[0, 512]
|
||||
end
|
||||
end
|
||||
|
||||
def test_split_name
|
||||
assert_equal ['b' * 100, 'a' * 155],
|
||||
|
|
Loading…
Reference in a new issue