switest 0.3.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: 3c144f6162bbe043cadc3c2743542ff52b0b9c2ef7d9ac2b694fe88cd1db1ebb
4
- data.tar.gz: f99e71cbfd40ae2baf0ad5eab7b8864a66f01c611e612d843a7482fa642c3d6d
3
+ metadata.gz: 056e2a1dd0271f490fdfb77978cdb272b8ac79f592aa18818642956d12f7c1a8
4
+ data.tar.gz: 28ec935b623017b29b5bd2f6899d82b85a84b6ac7a452977f4f9cb25f6445b9d
5
5
  SHA512:
6
- metadata.gz: 4185e0b448059955f50cd699d095c12666197daf13efa83a203aebfd2d0a3515e287bc7d0334c651f4a967f89181ae0252030f00a07d2f0e354ac3989a6e13ef
7
- data.tar.gz: 661109e09e38b8fbed7eeb32ceb7c664046d1fda387d77b85f832d2fe172d8cc0dc47882d3df00bb76351082e32490a66e781ace96d8f50e471048e32463988d
6
+ metadata.gz: 7dcffb0b3476237f826d7480251f00e70046197737d9886ea48a16dc886b463d1dfc83223858008fce51d14ab791e7d374252c43adf931a06ee95d114300d204
7
+ data.tar.gz: bded19bd55e5f76a7e2b93fa67f757e924f5f1bfe3b4089ab7c0c31ee8f74a4c97db7f9ce8437f2f6daf6da7790440ca941529a548f6e9905fc9699c668c3da4
data/README.md CHANGED
@@ -171,13 +171,21 @@ agent.end_reason # e.g. "NORMAL_CLEARING"
171
171
  assert_call(agent, timeout: 5) # Agent receives a call
172
172
  assert_no_call(agent, timeout: 2) # Agent does NOT receive a call
173
173
  assert_answered(agent, timeout: 5) # Call has been answered
174
- assert_bridged(agent, timeout: 5) # Call has been bridged
174
+ assert_bridged(agent, timeout: 5) # Call has been bridged (see note below)
175
175
  assert_hungup(agent, timeout: 5) # Call has ended
176
176
  assert_not_hungup(agent, timeout: 2) # Call is still active
177
177
  assert_dtmf(agent, "123", timeout: 5) # Agent receives expected DTMF digits
178
178
  assert_dtmf(agent, "123") { other.send_dtmf("123") } # With block: flushes stale DTMF first
179
179
  ```
180
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
+
181
189
  The `hangup_all` helper ends all active calls (useful before CDR assertions):
182
190
 
183
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")
@@ -78,9 +78,8 @@ module Switest
78
78
 
79
79
  if block
80
80
  agent.flush_dtmf
81
- task = Concurrent::ScheduledTask.execute(after) { block.call }
82
- received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
83
- task.wait
81
+ Concurrent::ScheduledTask.execute(after) { block.call }
82
+ received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout + after)
84
83
  else
85
84
  received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
86
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switest
4
- VERSION = "0.3.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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Relatel A/S