/usr/share/pcsd/test/test_session.rb is in pcs 0.9.149-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | require 'test/unit'
require 'pcsd_test_utils.rb'
require 'session.rb'
class TestSessionPool < Test::Unit::TestCase
def setup()
@env = {
'rack.multithread' => true,
}
end
def fixture_get_pool(lifetime)
pool = SessionPoolLifetime.new(nil, {:expire_after => lifetime,})
(1..3).each { |i| pool.set_session(@env, "sid#{i}", {'value' => i}, {}) }
return pool
end
def test_drop_expired_on_get()
lifetime = 2
pool = fixture_get_pool(lifetime)
# touch sessions each second
lifetime.times {
sleep(1)
assert_equal({'value' => 1}, pool.get_session(@env, 'sid1')[1])
assert_equal({'value' => 3}, pool.get_session(@env, 'sid3')[1])
}
# after @lifetime passes the unused session gets removed on access
sleep(1)
assert_equal({'value' => 1}, pool.get_session(@env, 'sid1')[1])
assert_equal({'value' => 3}, pool.get_session(@env, 'sid3')[1])
assert_equal({}, pool.get_session(@env, 'sid2')[1])
end
def test_drop_expired_explicit()
lifetime = 2
pool = fixture_get_pool(lifetime)
# touch sessions each second (otherwise they will be removed on access)
lifetime.times {
sleep(1)
pool.get_session(@env, 'sid2')
pool.set_session(@env, 'sid3', {'value' => 33}, {})
}
sleep(1)
pool.drop_expired(@env)
assert_equal(
{
'sid2' => {'value' => 2,},
'sid3' => {'value' => 33,},
},
pool.pool
)
end
def test_no_lifetime()
pool = fixture_get_pool(nil)
sleep(1)
assert_equal({'value' => 1}, pool.get_session(@env, 'sid1')[1])
assert_equal({'value' => 2}, pool.get_session(@env, 'sid2')[1])
assert_equal({'value' => 3}, pool.get_session(@env, 'sid3')[1])
sleep(1)
pool.drop_expired(@env)
assert_equal({'value' => 1}, pool.get_session(@env, 'sid1')[1])
assert_equal({'value' => 2}, pool.get_session(@env, 'sid2')[1])
assert_equal({'value' => 3}, pool.get_session(@env, 'sid3')[1])
end
end
|