Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Fixed blockwise transfers and added some optional ETSI Plugtests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Feb 13, 2015
1 parent b865acd commit 1b3d969
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 30 deletions.
6 changes: 3 additions & 3 deletions benchmarks/rackup/interop.ru
@@ -1,11 +1,11 @@
#\ -o ::1 -p 5683 -O Block=false -O Multicast=false -O Observe=false -O Log=debug -E none

module David; module Interop; end; end
module David; module ETSI; end; end

require 'bundler/setup'
Bundler.setup

require 'david'
require 'david/interop/mandatory_etsi/rack'
require 'david/etsi/mandatory/rack'

run David::Interop::MandatoryETSI::Rack.new
run David::ETSI::Mandatory::Rack.new
5 changes: 5 additions & 0 deletions lib/david/etsi.rb
@@ -0,0 +1,5 @@
module David::ETSI
end

require 'david/etsi/mandatory'
require 'david/etsi/optional'
4 changes: 4 additions & 0 deletions lib/david/etsi/mandatory.rb
@@ -0,0 +1,4 @@
module David::ETSI::Mandatory
path = File.expand_path('../mandatory', __FILE__)
Dir["#{path}/*.rb"].each { |file| require file }
end
@@ -1,4 +1,4 @@
module David::Interop::MandatoryETSI
module David::ETSI::Mandatory
class Grape < ::Grape::API
content_type :txt, 'text/plain'
default_format :txt
Expand Down
@@ -1,4 +1,4 @@
module David::Interop::MandatoryETSI
module David::ETSI::Mandatory
class Hobbit < ::Hobbit::Base
get '/test' do
response.status = 2.05
Expand Down
@@ -1,4 +1,4 @@
module David::Interop::MandatoryETSI
module David::ETSI::Mandatory
class NYNY < ::NYNY::App
before { headers['Content-Type'] = 'text/plain' }

Expand Down
@@ -1,6 +1,6 @@
module David::Interop::MandatoryETSI
module David::ETSI::Mandatory
class Rack
EMPTY_CONTENT = [2.05, {'Content-Type' => 'text/plain'}, []]
EMPTY_CONTENT = [2.05, {'Content-Type' => 'text/plain'}, ['foo']]

def call(env)
return case request(env)
Expand Down
@@ -1,4 +1,4 @@
module David::Interop::MandatoryETSI
module David::ETSI::Mandatory
class Sinatra < ::Sinatra::Base
before { content_type 'text/plain' }

Expand Down
4 changes: 4 additions & 0 deletions lib/david/etsi/optional.rb
@@ -0,0 +1,4 @@
module David::ETSI::Optional
path = File.expand_path('../optional', __FILE__)
Dir["#{path}/*.rb"].each { |file| require file }
end
26 changes: 26 additions & 0 deletions lib/david/etsi/optional/rack.rb
@@ -0,0 +1,26 @@
module David::ETSI::Optional
class Rack
def call(env)
return case request(env)
when 'GET /large'
[2.05, {'Content-Type' => 'text/plain'}, ['*'*1025]]
when 'GET /obs'
[2.05,
{
'Content-Type' => 'text/plain',
'ETag' => rand(0xffff).to_s
},
[Time.now.to_s]
]
else
[4.04, {}, []]
end
end

private

def request(env)
env['REQUEST_METHOD'] + ' ' + env['PATH_INFO']
end
end
end
4 changes: 0 additions & 4 deletions lib/david/interop.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/david/interop/mandatory_etsi.rb

This file was deleted.

8 changes: 5 additions & 3 deletions lib/david/registry.rb
Expand Up @@ -15,9 +15,11 @@ def log
# Celluloid::Actor[:gc]
# end

# def observe
# Celluloid::Actor[:observe]
# end
def observe
# Supervision is only initialized from here in tests.
Observe.supervise_as(:observe) if Celluloid::Actor[:observe].nil?
Celluloid::Actor[:observe]
end

def server
Celluloid::Actor[:server]
Expand Down
14 changes: 5 additions & 9 deletions spec/interop/mandatory_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'

[
Interop::MandatoryETSI::Grape,
Interop::MandatoryETSI::Hobbit,
Interop::MandatoryETSI::NYNY,
Interop::MandatoryETSI::Rack,
Interop::MandatoryETSI::Sinatra,
ETSI::Mandatory::Grape,
ETSI::Mandatory::Hobbit,
ETSI::Mandatory::NYNY,
ETSI::Mandatory::Rack,
ETSI::Mandatory::Sinatra,
Rails.application
].each do |app|
describe "ETSI Plugstests, Mandatory, #{app.to_s.split('::').last}" do
Expand Down Expand Up @@ -50,10 +50,6 @@
end
end

context 'TD_COAP_CORE_09' do
pending
end

it 'TD_COAP_CORE_10' do
token = rand(0xffffffff)
mid, response = req(:get, '/test', token: token)
Expand Down
113 changes: 113 additions & 0 deletions spec/interop/optional_spec.rb
@@ -0,0 +1,113 @@
require 'spec_helper'

[
ETSI::Optional::Rack,
].each do |app|
describe "ETSI Plugstests, Optional, #{app.to_s.split('::').last}" do
let!(:server) { supervised_server(:MinimalMapping => true, app: app) }

context 'TD_COAP_BLOCK_01' do
it 'block 0' do
mid, response = req(:get, '/large', block2: 0) # 0, false, 16
block = CoAP::Block.new(response.options[:block2]).decode

expect(response).to be_a(CoAP::Message)
expect(response.mcode).to eq([2, 5])
expect(response.mid).to eq(mid)
expect(response.payload.size).to eq(16)
expect(block.num).to eq(0)
expect(block.more).to eq(true)
expect(block.size).to eq(16)
end

it 'block 1' do
mid, response = req(:get, '/large', block2: 16) # 1, false, 16
block = CoAP::Block.new(response.options[:block2]).decode

expect(response).to be_a(CoAP::Message)
expect(response.mcode).to eq([2, 5])
expect(response.mid).to eq(mid)
expect(response.payload.size).to eq(16)
expect(block.num).to eq(1)
expect(block.more).to eq(true)
expect(block.size).to eq(16)
end

it 'block 64' do
mid, response = req(:get, '/large', block2: 1024) # 65, false, 16
block = CoAP::Block.new(response.options[:block2]).decode

expect(response).to be_a(CoAP::Message)
expect(response.mcode).to eq([2, 5])
expect(response.mid).to eq(mid)
expect(response.payload.size).to eq(1)
expect(block.num).to eq(64)
expect(block.more).to eq(false)
expect(block.size).to eq(16)
end

end

context 'TD_COAP_BLOCK_02' do
it 'block 0' do
mid, response = req(:get, '/large')
block = CoAP::Block.new(response.options[:block2]).decode

expect(response).to be_a(CoAP::Message)
expect(response.mcode).to eq([2, 5])
expect(response.mid).to eq(mid)
expect(response.payload.size).to eq(1024)
expect(block.num).to eq(0)
expect(block.more).to eq(true)
expect(block.size).to eq(1024)
end

it 'block 1' do
mid, response = req(:get, '/large', block2: 22) # 1, false, 1024
block = CoAP::Block.new(response.options[:block2]).decode

expect(response).to be_a(CoAP::Message)
expect(response.mcode).to eq([2, 5])
expect(response.mid).to eq(mid)
expect(response.payload.size).to eq(1)
expect(block.num).to eq(1)
expect(block.more).to eq(false)
expect(block.size).to eq(1024)
end
end

describe 'TD_COAP_OBS_01' do
before do
@answers = []

@t1 = Thread.start do
CoAP::Client.new.observe \
'/obs', '::1', nil,
->(s, m) { @answers << m }
end

Timeout.timeout(12) do
sleep 0.25 while !(@answers.size > 2)
end
end

it 'responses' do
expect(@answers.size).to be > 2
@answers.each do |answer|
obs = answer.options[:observe]
expect(obs).not_to eq(nil)
expect(obs).to be >= 0
expect(obs).to be <= 2
end
end

after do
@t1.kill
end
end

after do
server.terminate
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -13,7 +13,7 @@
$:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))

require 'david'
require 'david/interop'
require 'david/etsi'

module David
module TestHelper
Expand Down

0 comments on commit 1b3d969

Please sign in to comment.