rsmp 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rsmp/site_proxy_wait.rb +116 -103
- data/lib/rsmp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a57d963e9f3f6f4dccdfbfaf7bc2d4c09fcbae56d1ec886ed699faa373e054ed
|
4
|
+
data.tar.gz: 4035d49f738d335f94d4df8c9dd33a3744d258740e51df55be9da5998ce3e538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94e7df5ad072745c960726053e0630b8b9efefc87c746a0f96afb53c32c4ff7450a553d3576a9ad9cd430640355e8ff329862cb4fd24da8338780e500f3c0245
|
7
|
+
data.tar.gz: 70b0a93eb41dca5cfabe62cacfb08f675fe2f359886bc4038aa647a95d873553b04056277ee08bac16476c441c7b6f646300179567fe2b33f58aa83121456b37
|
data/Gemfile.lock
CHANGED
data/lib/rsmp/site_proxy_wait.rb
CHANGED
@@ -2,6 +2,113 @@
|
|
2
2
|
module RSMP
|
3
3
|
module SiteProxyWait
|
4
4
|
|
5
|
+
class Matcher
|
6
|
+
attr_reader :result, :messages
|
7
|
+
|
8
|
+
# Initialize with a list a wanted statuses
|
9
|
+
def initialize want, options={}
|
10
|
+
@want = want.clone
|
11
|
+
@result = {}
|
12
|
+
@messages = []
|
13
|
+
@m_id = options[:m_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Check if a messages is wanted.
|
17
|
+
# Returns true when we found all that we want.
|
18
|
+
def process message
|
19
|
+
ack_status = check_not_ack message
|
20
|
+
return ack_status if ack_status != nil
|
21
|
+
|
22
|
+
add = false
|
23
|
+
@want.each_with_index do |query,i| # look through wanted
|
24
|
+
get_items(message).each do |input| # look through status items in message
|
25
|
+
matching = match? query, input
|
26
|
+
if matching == true
|
27
|
+
@result[query] = input
|
28
|
+
add = true
|
29
|
+
elsif matching == false
|
30
|
+
@result.delete query
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@messages << message if add
|
35
|
+
@result.size == @want.size # queries left to match?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check for MessageNotAck
|
39
|
+
# If the original request identified by @m_id is rejected, we abort
|
40
|
+
def check_not_ack message
|
41
|
+
if message.is_a?(MessageNotAck)
|
42
|
+
if message.attribute('oMId') == @m_id
|
43
|
+
# Set result to an exception, but don't raise it.
|
44
|
+
# This will be returned by the async task and stored as the task result
|
45
|
+
# When the parent task call wait() on the task, the exception
|
46
|
+
# will be raised in the parent task, and caught by RSpec.
|
47
|
+
# RSpec will then show the error and record the test as failed
|
48
|
+
m_id_short = RSMP::Message.shorten_m_id @m_id, 8
|
49
|
+
@result = RSMP::MessageRejected.new("#{type_str} #{m_id_short} was rejected: #{message.attribute('rea')}")
|
50
|
+
@messages = [message]
|
51
|
+
return true
|
52
|
+
end
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class CommandResponseMatcher < RSMP::SiteProxyWait::Matcher
|
59
|
+
def initialize want, options={}
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
def type_str
|
64
|
+
"Command request"
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_items message
|
68
|
+
message.attributes['rvs']
|
69
|
+
end
|
70
|
+
|
71
|
+
def match? query, item
|
72
|
+
return nil if query['cCI'] && query['cCI'] != item['cCI']
|
73
|
+
return nil if query['n'] && query['n'] != item['n']
|
74
|
+
if query['v'].is_a? Regexp
|
75
|
+
return false if query['v'] && item['v'] !~ query['v']
|
76
|
+
else
|
77
|
+
return false if query['v'] && item['v'] != query['v']
|
78
|
+
end
|
79
|
+
true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Class for matching incoming messaging against a list of wanted statuses,
|
84
|
+
# and flagging when everything has been matched.
|
85
|
+
class StatusResponseMatcher < RSMP::SiteProxyWait::Matcher
|
86
|
+
def initialize want, options={}
|
87
|
+
super
|
88
|
+
end
|
89
|
+
|
90
|
+
def type_str
|
91
|
+
"Status request"
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_items message
|
95
|
+
message.attributes['sS']
|
96
|
+
end
|
97
|
+
|
98
|
+
# Match an item against a query
|
99
|
+
def match? query, item
|
100
|
+
return nil if query['sCI'] && query['sCI'] != item['sCI']
|
101
|
+
return nil if query['n'] && query['n'] != item['n']
|
102
|
+
return false if query['q'] && query['q'] != item['q']
|
103
|
+
if query['s'].is_a? Regexp
|
104
|
+
return false if query['s'] && item['s'] !~ query['s']
|
105
|
+
else
|
106
|
+
return false if query['s'] && item['s'] != query['s']
|
107
|
+
end
|
108
|
+
true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
5
112
|
def wait_for_alarm parent_task, options={}
|
6
113
|
matching_alarm = nil
|
7
114
|
message = collect(parent_task,options.merge(type: "Alarm", with_message: true, num: 1)) do |message|
|
@@ -29,120 +136,26 @@ module RSMP
|
|
29
136
|
|
30
137
|
def collect_command_responses parent_task, options, m_id
|
31
138
|
task.annotate "wait for command response"
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
collect(parent_task,options.merge({
|
36
|
-
type: ['CommandResponse','MessageNotAck'],
|
37
|
-
num: 1
|
38
|
-
})) do |message|
|
39
|
-
if message.is_a?(MessageNotAck)
|
40
|
-
if message.attribute('oMId') == m_id
|
41
|
-
# set result to an exception, but don't raise it.
|
42
|
-
# this will be returned by the task and stored as the task result
|
43
|
-
# when the parent task call wait() on the task, the exception
|
44
|
-
# will be raised in the parent task, and caught by rspec.
|
45
|
-
# rspec will then show the error and record the test as failed
|
46
|
-
m_id_short = RSMP::Message.shorten_m_id m_id, 8
|
47
|
-
result = RSMP::MessageRejected.new "Command request #{m_id_short} was rejected: #{message.attribute('rea')}"
|
48
|
-
next true # done, no more messages wanted
|
49
|
-
else
|
50
|
-
false
|
51
|
-
end
|
52
|
-
else
|
53
|
-
add = false
|
54
|
-
# look through querues
|
55
|
-
want.each_with_index do |query,i|
|
56
|
-
# look through items in message
|
57
|
-
message.attributes['rvs'].each do |input|
|
58
|
-
matching = command_match? query, input
|
59
|
-
if matching == true
|
60
|
-
result[query] = input
|
61
|
-
add = true
|
62
|
-
elsif matching == false
|
63
|
-
result.delete query
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
messages << message if add
|
68
|
-
result.size == want.size # any queries left to match?
|
69
|
-
end
|
139
|
+
matcher = CommandResponseMatcher.new options[:command_list], m_id: m_id
|
140
|
+
collect(parent_task,options.merge(type: ['CommandResponse','MessageNotAck'], num: 1)) do |message|
|
141
|
+
matcher.process message # returns true when done (all queries matched)
|
70
142
|
end
|
71
|
-
return result, messages
|
143
|
+
return matcher.result, matcher.messages
|
72
144
|
rescue Async::TimeoutError
|
73
145
|
raise RSMP::TimeoutError.new "Did not receive correct command response to #{m_id} within #{options[:timeout]}s"
|
74
146
|
end
|
75
147
|
|
76
148
|
def collect_status_updates_or_responses task, type, options, m_id
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# wait for a status update
|
81
|
-
collect(task,options.merge({
|
82
|
-
type: [type,'MessageNotAck'],
|
83
|
-
num: 1
|
84
|
-
})) do |message|
|
85
|
-
if message.is_a?(MessageNotAck)
|
86
|
-
if message.attribute('oMId') == m_id
|
87
|
-
# set result to an exception, but don't raise it.
|
88
|
-
# this will be returned by the task and stored as the task result
|
89
|
-
# when the parent task call wait() on the task, the exception
|
90
|
-
# will be raised in the parent task, and caught by rspec.
|
91
|
-
# rspec will then show the error and record the test as failed
|
92
|
-
m_id_short = RSMP::Message.shorten_m_id m_id, 8
|
93
|
-
result = RSMP::MessageRejected.new "Status request #{m_id_short} was rejected: #{message.attribute('rea')}"
|
94
|
-
next true # done, no more messages wanted
|
95
|
-
end
|
96
|
-
false
|
97
|
-
else
|
98
|
-
found = []
|
99
|
-
add = false
|
100
|
-
# look through querues
|
101
|
-
want.each_with_index do |query,i|
|
102
|
-
# look through status items in message
|
103
|
-
message.attributes['sS'].each do |input|
|
104
|
-
matching = status_match? query, input
|
105
|
-
if matching == true
|
106
|
-
result[query] = input
|
107
|
-
add = true
|
108
|
-
elsif matching == false
|
109
|
-
result.delete query
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
messages << message if add
|
114
|
-
result.size == want.size # any queries left to match?
|
115
|
-
end
|
149
|
+
matcher = StatusResponseMatcher.new options[:status_list], m_id: m_id
|
150
|
+
collect(task,options.merge( type: [type,'MessageNotAck'], num: 1 )) do |message|
|
151
|
+
matcher.process message # returns true when done (all queries matched)
|
116
152
|
end
|
117
|
-
return result, messages
|
153
|
+
return matcher.result, matcher.messages
|
118
154
|
rescue Async::TimeoutError
|
119
155
|
type_str = {'StatusUpdate'=>'update', 'StatusResponse'=>'response'}[type]
|
120
156
|
raise RSMP::TimeoutError.new "Did not received correct status #{type_str} in reply to #{m_id} within #{options[:timeout]}s"
|
121
157
|
end
|
122
158
|
|
123
|
-
def status_match? query, item
|
124
|
-
return nil if query['sCI'] && query['sCI'] != item['sCI']
|
125
|
-
return nil if query['n'] && query['n'] != item['n']
|
126
|
-
return false if query['q'] && query['q'] != item['q']
|
127
|
-
if query['s'].is_a? Regexp
|
128
|
-
return false if query['s'] && item['s'] !~ query['s']
|
129
|
-
else
|
130
|
-
return false if query['s'] && item['s'] != query['s']
|
131
|
-
end
|
132
|
-
true
|
133
|
-
end
|
134
|
-
|
135
|
-
def command_match? query, item
|
136
|
-
return nil if query['cCI'] && query['cCI'] != item['cCI']
|
137
|
-
return nil if query['n'] && query['n'] != item['n']
|
138
|
-
if query['v'].is_a? Regexp
|
139
|
-
return false if query['v'] && item['v'] !~ query['v']
|
140
|
-
else
|
141
|
-
return false if query['v'] && item['v'] != query['v']
|
142
|
-
end
|
143
|
-
true
|
144
|
-
end
|
145
|
-
|
146
159
|
def wait_for_aggregated_status parent_task, options, m_id
|
147
160
|
collect(parent_task,options.merge({
|
148
161
|
type: ['AggregatedStatus','MessageNotAck'],
|
@@ -168,4 +181,4 @@ module RSMP
|
|
168
181
|
end
|
169
182
|
|
170
183
|
end
|
171
|
-
end
|
184
|
+
end
|
data/lib/rsmp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Tin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|