Class: Semilla::FlexUnitReportServer
- Inherits:
-
Object
- Object
- Semilla::FlexUnitReportServer
- Defined in:
- lib/semilla/report_server.rb
Constant Summary collapse
- START_ACK =
"<startOfTestRunAck/>"- END_TEST =
"<endOfTestRun/>"- END_TEST_ACK =
"<endOfTestRunAck/>"- POLICY_REQUEST =
"<policy-file-request/>"- EOF =
"\0"- SOCKET_POLICY_FILE =
<<EOS <?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-access-from domain="*" to-ports="@@@"/> </cross-domain-policy> EOS
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(port = 1026) ⇒ FlexUnitReportServer
constructor
A new instance of FlexUnitReportServer.
- #policyFile ⇒ Object
- #receiveWithTimeout(client, timeout) ⇒ Object
- #sendPolicyFile(client) ⇒ Object
- #start(timeout = 10) ⇒ Object
Constructor Details
#initialize(port = 1026) ⇒ FlexUnitReportServer
Returns a new instance of FlexUnitReportServer.
25 26 27 28 29 30 |
# File 'lib/semilla/report_server.rb', line 25 def initialize(port=1026) @port = port @addr = "127.0.0.1" @server = nil #This will be our socket server @error = false end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/semilla/report_server.rb', line 9 def error @error end |
#results ⇒ Object
Returns the value of attribute results.
8 9 10 |
# File 'lib/semilla/report_server.rb', line 8 def results @results end |
Instance Method Details
#policyFile ⇒ Object
126 127 128 |
# File 'lib/semilla/report_server.rb', line 126 def policyFile return SOCKET_POLICY_FILE.sub "@@@", @port #replace the @@@ for the port number end |
#receiveWithTimeout(client, timeout) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/semilla/report_server.rb', line 139 def receiveWithTimeout(client, timeout) begin r = Timeout::timeout timeout do client.recv(1024) end rescue Timeout::Error "" #Timed out, return an empty string end end |
#sendPolicyFile(client) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/semilla/report_server.rb', line 131 def sendPolicyFile(client) puts "Sending policy file." #Send policy stuff client.puts self.policyFile client.flush end |
#start(timeout = 10) ⇒ Object
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/semilla/report_server.rb', line 33 def start(timeout=10) @server = TCPServer.new(@addr, @port) #view server data puts @server.addr #open the socket puts "Opening server at port #{@port}" #-------------------------------------------------------------- #the report result will be here report = "" loop { puts "Waiting for client..." begin #Wait with a timeout client = Timeout::timeout timeout do @server.accept end #No client connected within the time limit, bail out rescue Timeout::Error puts "Timeout!!, no client connected!!!" @error = true break end puts "Client connected..." puts "Receiving data" #Tell FlexUnit to start sending stuff client.puts START_ACK + EOF #puts "[OUT] #{START_ACK}" report = "<report>" error = false while received = receiveWithTimeout(client, timeout) unless received != "" finished = true puts "empty data!!" error = true break end #puts received putc '.' #clean up the text received.rstrip! received.chomp! #print out for debug #puts "[IN] #{received}" #check for policy file if received.include? POLICY_REQUEST self.sendPolicyFile client client.close puts "[OUT] Sending policy File" break end if received.include? END_TEST #the last message may contain some data as well report = report + received.sub(END_TEST, "") puts puts "Closing connection" #Test ended, send ACK to client client.puts END_TEST_ACK + EOF client.flush client.close finished = true report = report + "</report>" break end report = report + received end if error report = nil end break if finished } #Parse the xml from flexunit and generate the report files. puts "bye bye" #sanitize the results string @results = report.delete "\000" unless report.nil? #--------------------------------------------------------------- end |