Sha256: bd6b2c085d74706bed3c745dce7d926ff23180204c05684f34b07ee9e885ada0

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')

$NITRO_NO_ENVIRONMENT = true

require 'ostruct'
require 'test/unit'

require 'glue'
require 'glue/cache/file'
require 'nitro/session'

class TC_Session < Test::Unit::TestCase # :nodoc: all
  include Nitro

  CACHES = [:memory, :file, :og]
  begin
    require 'glue/cache/memcached'
    Glue::MemCached.new
    CACHES << :memcached
  rescue Object # Errno::EBADF => e
    Logger.warn "skipping memcached test: server not running"
  end


  def test_create_id
    sid = Session.new.session_id
    assert_not_equal sid, Session.new.session_id
    assert_not_equal sid, Session.new.session_id
    assert_not_equal sid, Session.new.session_id
    assert_not_equal sid, Session.new.session_id
    assert_not_equal sid, Session.new.session_id
  end

  def test_gc
    CACHES.each do |cache_type|
      Session.keepalive = 2
      
      if :file == cache_type
        path = File.join(File.dirname(__FILE__), '..', 'cache')
        Glue::FileCache.basedir = path
        FileUtils.rm_r path if File.exists? path
      end

      Session.cache_type = cache_type

      if cache_type == :og
        Og.setup(:store => :sqlite, :destroy => true)
      end

      sessions = (1..2).collect do
        s = Session.new
  s.sync
  s
      end

      Session.cache.gc!
      sessions.each { |s| assert_not_nil(Session.cache[s.session_id]) }
      Session.cache.gc!
      sessions.each { |s| assert_not_nil(Session.cache[s.session_id]) }
      sleep(3)
      Session.cache.gc!    
      sessions.each { |s| assert_nil(Session.cache[s.session_id]) }
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.29.0 test/nitro/tc_session.rb