forked from sockjs/sockjs-ruby
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
159 lines (130 loc) · 3.92 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# vim: set ft=ruby :
require 'corundum/tasklibs'
module Corundum
Corundum::register_project(__FILE__)
core = Core.new
core.in_namespace do
GemspecFiles.new(core)
QuestionableContent.new(core) do |dbg|
dbg.words = %w{debug! debugger}
end
rspec = RSpec.new(core)
cov = SimpleCov.new(core, rspec) do |cov|
cov.threshold = 70
cov.coverage_filter = proc do |path|
/\.rb$/ =~ path and /version/ !~ path
end
end
gem = GemBuilding.new(core)
cutter = GemCutter.new(core,gem)
email = Email.new(core)
vc = Git.new(core) do |vc|
vc.branch = "master"
end
yd = YARDoc.new(core)
docs = DocumentationAssembly.new(core, yd, rspec, cov)
pages = GithubPages.new(docs)
end
end
task :default => [:release, :publish_docs]
# Get list of all the tests in format for TODO.todo.
task :unpack_tests do
version = "0.2.1"
tests = {}
File.foreach("protocol/sockjs-protocol-#{version}.py").each_with_object(tests) do |line, buffer|
if line.match(/class (\w+)\(Test\)/)
buffer[$1] = Array.new
elsif line.match(/def (\w+)/)
if buffer.keys.last
buffer[buffer.keys.last] << $1
end
end
end
require "yaml"
puts tests.to_yaml
end
desc "Run the protocol tests from https://github.com/sockjs/sockjs-protocol"
task :protocol_test, [:port] => 'protocol_test:run'
namespace :protocol_test do
task :run, [:port] => [:collect_args, :client] do |task, args|
end
task :collect_args, [:port] do |task, args|
$TEST_PORT = (args[:port] || ENV["TEST_PORT"] || 8081)
end
task :check_port do
begin
test_conn = TCPSocket.new 'localhost', $TEST_PORT
fail "Something is still running on localhost:#$TEST_PORT"
rescue Errno::ECONNREFUSED
#That's what we're hoping for
ensure
test_conn.close rescue nil
end
end
task :run_server => :check_port do
$server_pid = Process::fork do
Rake::application.invoke_task "protocol_test:server[#$TEST_PORT]"
end
%w{EXIT TERM}.each do |signal|
trap(signal) do
puts "Killing #$server_pid"
sh "ps -lwwwf #$server_pid"
Process::kill('TERM', $server_pid)
sleep 1
Process::kill('TERM', $server_pid)
Process::wait($server_pid)
end
end
begin_time = Time.now
begin
test_conn = TCPSocket.new 'localhost', $TEST_PORT
rescue Errno::ECONNREFUSED
if Time.now - begin_time > 10
raise "Couldn't connect to test server in 10 seconds - bailing out"
else
retry
end
ensure
test_conn.close rescue nil
end
end
task :client => :run_server do
proto_version = ENV["PROTO_VERSION"] ||
begin
require 'sockjs/version'
SockJS::PROTOCOL_VERSION_STRING
end
sh "protocol/venv/bin/python protocol/sockjs-protocol-#{proto_version}.py #{ENV["FOCUSED_TESTS"]}" do |ok, res|
if not ok
puts "Protocol test suite returned failures (#{res})"
end
end
end
desc "Run the protocol test server"
task :server, [:port] do |task, args|
require "thin"
require 'em/pure_ruby'
#require "eventmachine"
require 'sockjs/examples/protocol_conformance_test'
$DEBUG = true
PORT = Integer(args[:port] || 8081)
::Thin::Connection.class_eval do
def handle_error(error = $!)
log "[#{error.class}] #{error.message}\n - "
log error.backtrace.join("\n - ")
close_connection rescue nil
end
end
SockJS.debug!
SockJS.debug "Available handlers: #{::SockJS::Endpoint.endpoints.inspect}"
protocol_version = args[:version] || SockJS::PROTOCOL_VERSION_STRING
options = {sockjs_url: "http://cdn.sockjs.org/sockjs-#{protocol_version}.min.js"}
puts "\n#{__FILE__}:#{__LINE__} => #{options.inspect}"
app = SockJS::Examples::ProtocolConformanceTest.build_app(options)
begin
Thin::Server.start(app, PORT)
rescue => ex
p ex.message
end
end
end