Sha256: 72a20dc7c3a023473a9057518133c44a0786085b6d293db473e6ecead6176ac9

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require File.join(File.dirname(__FILE__), 'CONFIG.rb')

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

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.30.0 test/nitro/tc_session.rb
nitro-0.31.0 test/nitro/tc_session.rb