switest 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46d12432ffab240a974d72b3dd40c644881db795afdf01f0907837bf6a07f749
4
- data.tar.gz: 599397a725f50b57b243a42a451b8dea72497fbc86fd8dd2908096627a22e097
3
+ metadata.gz: 056e2a1dd0271f490fdfb77978cdb272b8ac79f592aa18818642956d12f7c1a8
4
+ data.tar.gz: 28ec935b623017b29b5bd2f6899d82b85a84b6ac7a452977f4f9cb25f6445b9d
5
5
  SHA512:
6
- metadata.gz: a409ab5e4948ac6bd38518f3a5bcbbaac61e8154ce6e162916f0ae0fa66ab819b68f0f3cf073127703ebb38741d616c8437f3a1a3cebad376d6d240b188eb6cd
7
- data.tar.gz: eda147e356709c794896b2e274b2bf7e74f15dc42c422e5898255ec8c62c112deb5f8249cded86b056257a91befc1f65a498ff76eb680dfa6584b0631a871e01
6
+ metadata.gz: 7dcffb0b3476237f826d7480251f00e70046197737d9886ea48a16dc886b463d1dfc83223858008fce51d14ab791e7d374252c43adf931a06ee95d114300d204
7
+ data.tar.gz: bded19bd55e5f76a7e2b93fa67f757e924f5f1bfe3b4089ab7c0c31ee8f74a4c97db7f9ce8437f2f6daf6da7790440ca941529a548f6e9905fc9699c668c3da4
data/README.md CHANGED
@@ -168,14 +168,24 @@ agent.end_reason # e.g. "NORMAL_CLEARING"
168
168
  `Switest::Scenario` provides these assertions:
169
169
 
170
170
  ```ruby
171
- assert_call(agent, timeout: 5) # Agent receives a call
172
- assert_no_call(agent, timeout: 2) # Agent does NOT receive a call
173
- assert_hungup(agent, timeout: 5) # Call has ended
174
- assert_not_hungup(agent, timeout: 2) # Call is still active
175
- assert_dtmf(agent, "123", timeout: 5) # Agent receives expected DTMF digits
171
+ assert_call(agent, timeout: 5) # Agent receives a call
172
+ assert_no_call(agent, timeout: 2) # Agent does NOT receive a call
173
+ assert_answered(agent, timeout: 5) # Call has been answered
174
+ assert_bridged(agent, timeout: 5) # Call has been bridged (see note below)
175
+ assert_hungup(agent, timeout: 5) # Call has ended
176
+ assert_not_hungup(agent, timeout: 2) # Call is still active
177
+ assert_dtmf(agent, "123", timeout: 5) # Agent receives expected DTMF digits
176
178
  assert_dtmf(agent, "123") { other.send_dtmf("123") } # With block: flushes stale DTMF first
177
179
  ```
178
180
 
181
+ **Note on `assert_bridged`:** This assertion only works when a CHANNEL_BRIDGE
182
+ event fires on a channel Switest tracks. It works when the FreeSWITCH dialplan
183
+ runs the `bridge` application on an inbound channel picked up via
184
+ `listen_for_call`. It does **not** work for agent-to-agent calls routed through
185
+ SIP gateways — the bridge happens on internal gateway legs whose UUIDs Switest
186
+ doesn't track. For gateway scenarios, use `assert_answered` on both agents
187
+ instead to confirm the call is connected.
188
+
179
189
  The `hangup_all` helper ends all active calls (useful before CDR assertions):
180
190
 
181
191
  ```ruby
@@ -39,16 +39,24 @@ module Switest
39
39
 
40
40
  # Hangup all active calls individually and wait for them to end.
41
41
  # This ensures proper hangup_cause is set for each call (important for CDRs).
42
+ # Sends all hangups first, then waits with a shared deadline to avoid
43
+ # O(n * timeout) delays with many calls.
42
44
  def hangup_all(cause: "NORMAL_CLEARING", timeout: 5)
43
45
  return unless @connection&.connected?
44
46
 
45
- @calls.each_value do |call|
46
- next if call.ended?
47
- begin
48
- call.hangup(cause, wait: timeout)
49
- rescue
50
- # Ignore errors during cleanup
51
- end
47
+ active = @calls.values.reject(&:ended?)
48
+
49
+ # Send all hangups without waiting
50
+ active.each do |call|
51
+ call.hangup(cause, wait: false) rescue nil
52
+ end
53
+
54
+ # Wait for all to end with a single shared deadline
55
+ deadline = Time.now + timeout
56
+ active.each do |call|
57
+ remaining = deadline - Time.now
58
+ break if remaining <= 0
59
+ call.wait_for_end(timeout: remaining) unless call.ended?
52
60
  end
53
61
  end
54
62
 
@@ -110,8 +110,11 @@ module Switest
110
110
 
111
111
  def subscribe_events
112
112
  events = %w[
113
- CHANNEL_CREATE CHANNEL_ANSWER CHANNEL_BRIDGE CHANNEL_HANGUP
114
- CHANNEL_HANGUP_COMPLETE CHANNEL_EXECUTE_COMPLETE DTMF CHANNEL_STATE
113
+ CHANNEL_CREATE # Detect new inbound calls
114
+ CHANNEL_ANSWER # Track when calls are answered
115
+ CHANNEL_BRIDGE # Track when calls are bridged
116
+ CHANNEL_HANGUP_COMPLETE # Track call end with final headers
117
+ DTMF # Receive DTMF digits per call
115
118
  ].join(" ")
116
119
 
117
120
  @socket.write("event plain #{events}\n\n")
@@ -49,6 +49,18 @@ module Switest
49
49
  refute agent.call?, "Expected agent to not have received a call"
50
50
  end
51
51
 
52
+ def assert_answered(agent, timeout: 5)
53
+ assert agent.call?, "Agent has no call"
54
+ success = agent.wait_for_answer(timeout: timeout)
55
+ assert success, "Expected call to be answered within #{timeout} seconds"
56
+ end
57
+
58
+ def assert_bridged(agent, timeout: 5)
59
+ assert agent.call?, "Agent has no call"
60
+ success = agent.wait_for_bridge(timeout: timeout)
61
+ assert success, "Expected call to be bridged within #{timeout} seconds"
62
+ end
63
+
52
64
  def assert_hungup(agent, timeout: 5)
53
65
  assert agent.call?, "Agent has no call"
54
66
  success = agent.wait_for_end(timeout: timeout)
@@ -66,9 +78,8 @@ module Switest
66
78
 
67
79
  if block
68
80
  agent.flush_dtmf
69
- task = Concurrent::ScheduledTask.execute(after) { block.call }
70
- received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
71
- task.wait
81
+ Concurrent::ScheduledTask.execute(after) { block.call }
82
+ received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout + after)
72
83
  else
73
84
  received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
74
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switest
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Relatel A/S