• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

修订版d36b20955a253bea5759010ecf0af259e1a1935a (tree)
时间2011-12-12 22:10:09
作者Daigo Moriwaki <beatles@user...>
CommiterDaigo Moriwaki

Log Message

Improved robustness of test/benchmark.rb.

更改概述

差异

--- a/shogi-server
+++ b/shogi-server
@@ -420,7 +420,10 @@ def main
420420 client.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
421421 # Keepalive time can be set by /proc/sys/net/ipv4/tcp_keepalive_time
422422 player, login = login_loop(client) # loop
423- next unless player
423+ unless player
424+ log_error("Detected a timed out login attempt")
425+ next
426+ end
424427
425428 log_message(sprintf("user %s login", player.name))
426429 login.process
--- a/test/benchmark.rb
+++ b/test/benchmark.rb
@@ -1,14 +1,18 @@
11 #!/usr/bin/ruby
22
3+require 'logger'
34 require 'socket'
45 require 'thread'
56
7+$logger = nil
8+
69 class BenchPlayer
710 def initialize(game_name, name, sente)
811 @game_name = game_name
912 @name = "%s_%s" % [game_name, name]
1013 @turn_mark = sente ? "+" : "-"
1114 @nmoves = 0
15+ @socket = nil
1216 end
1317 attr_reader :nmoves
1418
@@ -22,37 +26,42 @@ class BenchPlayer
2226
2327 def reader
2428 Thread.new do
29+ Thread.pass
2530 loop do
26- if r = select([@socket], nil, nil, 10)
31+ if r = select([@socket], nil, nil, 300)
2732 str = r[0].first.gets
2833 if %r!^[\+\-]\d{4}\w{2},T\d+$! =~ str
2934 @nmoves += 1
3035 end
31- @message << str
36+ @message << str if str
3237 else
33- raise "timed out"
38+ $logger.warn "Timed out: %s" % [@name]
3439 end
3540 end
41+ $logger.error "Socket error: %s" % [@name]
3642 end
3743 end
3844
3945 def wait(reg)
4046 loop do
4147 break if reg =~ @message
42- sleep 0.1
48+ #$logger.debug "WAIT %s: %s" % [reg, @message]
49+ sleep 0.001
50+ #Thread.pass
4351 end
4452 end
4553
4654 def wait_nmoves(n)
4755 loop do
4856 break if @nmoves == n
49- sleep 0.01
57+ sleep 0.001
58+ #Thread.pass
5059 end
5160 end
5261
5362 def login
5463 @socket.puts "LOGIN #{@name} dummy x1"
55- wait %r!^LOGIN!
64+ wait %r!^##\[LOGIN\] \+OK!
5665 end
5766
5867 def game
@@ -94,12 +103,20 @@ class BenchGame
94103 end
95104
96105 def start
106+ $logger.info "Starting... %s" % [@game_name]
107+ $logger.debug "Connecting... %s" % [@game_name]
97108 each_player {|player| player.connect}
109+ $logger.debug "Logging in... %s" % [@game_name]
98110 each_player {|player| player.login}
111+ $logger.debug "Sending GAME... %s" % [@game_name]
99112 each_player {|player| player.game}
113+ $logger.debug "Waiting... %s" % [@game_name]
100114 each_player {|player| player.wait %r!^END Game_Summary!}
115+ $logger.debug "Agreeing... %s" % [@game_name]
101116 each_player {|player| player.agree}
117+ $logger.debug "AGREE waiting... %s" % [@game_name]
102118 each_player {|player| player.wait %r!^START:!}
119+ $logger.info "Started %s" % [@game_name]
103120 turn = true # black
104121 nmoves = 0
105122 @csa.each_line do |line|
@@ -115,10 +132,15 @@ class BenchGame
115132 turn = true
116133 nmoves += 1
117134 when /^%TORYO/
135+ $logger.debug "Waiting TORYO... %s" % [@game_name]
136+ @p1.wait_nmoves nmoves
137+ @p2.wait_nmoves nmoves
118138 turn ? @p1.toryo : @p2.toryo
119139 end
120140 end
141+ $logger.info "Logging out... %s" % [@game_name]
121142 each_player {|player| player.logout}
143+ $logger.info "Finished %s" % [@game_name]
122144 end
123145 end
124146
@@ -127,11 +149,15 @@ if __FILE__ == $0
127149 filepath = ARGV.shift || File.join(File.dirname(__FILE__), "csa", "wdoor+floodgate-900-0+gps_normal+gps_l+20100507120007.csa")
128150 csa = File.open(filepath){|f| f.read}
129151
152+ $logger = Logger.new(STDOUT)
153+ $logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
154+
130155 nclients = ARGV.shift || 1
131156 nclients = nclients.to_i
132157 threads = []
133158 nclients.times do |i|
134159 threads << Thread.new do
160+ Thread.pass
135161 game = BenchGame.new("b#{i}", csa)
136162 game.start
137163 end