Skip to content

Instantly share code, notes, and snippets.

@nog
Last active March 10, 2019 08:11
Show Gist options
  • Save nog/56f97baddb0d63c6cb2aed876ba4e2fc to your computer and use it in GitHub Desktop.
Save nog/56f97baddb0d63c6cb2aed876ba4e2fc to your computer and use it in GitHub Desktop.
Threadsafeの検証をしようとしてこれだけでは上手くいかなかったSpec
describe Jpmobile::ParamsFilter do
include Rack::Test::Methods
include Jpmobile::RackHelper
include Jpmobile::Util
context 'Threadで動作している時' do
before(:all) do
@app = Jpmobile::MobileCarrier.new(Jpmobile::ParamsFilter.new(UnitApplication.new))
@form_params = {
'bar' => 'baz',
'hoge' => 'hige',
'hage' => 'hige',
}
@form_string = @form_params.map {|k, v|
'%s=%s' % [utf8_to_sjis(k), utf8_to_sjis(v)]
}.join('&')
@mobile_request = Rack::MockRequest.env_for(
"/?guid=ON&id=1",
'REQUEST_METHOD' => 'POST',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)',
:input => @form_string,
)
@not_mobile_request = Rack::MockRequest.env_for(
"/?guid=ON&id=1",
'REQUEST_METHOD' => 'GET',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
)
end
it '正しいレスポンスが帰る' do
threads = []
10.times do
10.times do
threads.push(Thread.new{
sleep 0.5 * rand
res = @app.call(@mobile_request)
expect(res[0]).to eq(200)
})
end
100.times do
threads.push(Thread.new{
sleep 0.5 * rand
res = @app.call(@not_mobile_request)
expect(res[0]).to eq(200)
})
end
end
threads.each{|t| t.join }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment