Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created March 29, 2011 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagomoris/891745 to your computer and use it in GitHub Desktop.
Save tagomoris/891745 to your computer and use it in GitHub Desktop.
ldap接続を15分前後アイドルにして、その次のクエリが失敗するかどうかのテスト
#!/usr/bin/env ruby
require 'ldap'
SERVER_NAME = '192.168.0.128'
SERVER_PORT = 389
AUTH_DN = 'cn=binduser,cn=Users,dc=ad,dc=livedoor,dc=intranet'
AUTH_PASS = 'yourpassword'
def connection
conn = LDAP::Conn.new(SERVER_NAME, SERVER_PORT)
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
conn.bind(AUTH_DN, AUTH_PASS)
conn
end
def try_search(conn)
begin
result = conn.search2('ou=LD Users,dc=ad,dc=livedoor,dc=intranet', LDAP::LDAP_SCOPE_SUBTREE, "(MAIL=tagomoris@livedoor.jp)")
result.size > 0
rescue LDAP::ResultError
return false
end
end
def print_now(msg, from)
secs = Time.now - from
print sprintf("%02d min, %02d secs : ", secs / 60, secs % 60) + msg + "\n"
end
(0..120).to_a.shuffle.each do |x|
sleep rand(6)
fork {
conn = connection()
raise RuntimeError, "Failed to init searching" unless try_search(conn)
from = Time.now
sleep 60 * 14 + x
result = try_search(conn)
print_now("wait and seach: " + result.to_s, from)
conn.unbind()
}
end
Process.waitall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment