summaryrefslogtreecommitdiff
path: root/test/test_securerandom.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_securerandom.rb')
-rw-r--r--test/test_securerandom.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/test/test_securerandom.rb b/test/test_securerandom.rb
index e4a0e17365..765fbc9e0d 100644
--- a/test/test_securerandom.rb
+++ b/test/test_securerandom.rb
@@ -1,20 +1,23 @@
# frozen_string_literal: false
require 'test/unit'
require 'securerandom'
-require_relative 'ruby/test_random_formatter'
# This testcase does NOT aim to test cryptographically strongness and randomness.
class TestSecureRandom < Test::Unit::TestCase
- include Random::Formatter::FormatterTest
- include Random::Formatter::NotDefaultTest
def setup
@it = SecureRandom
end
-# This test took 2 minutes on my machine.
-# And 65536 times loop could not be enough for forcing PID recycle.
-if false
+ def test_alphanumeric_with_chars
+ assert_nothing_raised(ArgumentError) do
+ @it.alphanumeric(1, chars: ("0".."9").to_a)
+ end
+ end
+
+ # This test took 2 minutes on my machine.
+ # And 65536 times loop could not be enough for forcing PID recycle.
+ # TODO: We should run this test only on GitHub Actions.
def test_s_random_bytes_is_fork_safe
begin
require 'openssl'
@@ -24,7 +27,7 @@ if false
SecureRandom.random_bytes(8)
pid, v1 = forking_random_bytes
assert(check_forking_random_bytes(pid, v1), 'Process ID not recycled?')
- end
+ end if false # ENV["CI"] && RUBY_PLATFORM =~ /darwin/ && `sw_vers -productVersion`.to_i > 13 # for Apple Silicon
def forking_random_bytes
r, w = IO.pipe
@@ -41,7 +44,7 @@ if false
end
def check_forking_random_bytes(target_pid, target)
- 65536.times do
+ (65536 * 1.5).to_i.times do
pid = fork {
if $$ == target_pid
v2 = SecureRandom.random_bytes(8)
@@ -63,7 +66,6 @@ if false
end
false # not recycled?
end
-end
def test_with_openssl
begin