Skip to content

Commit

Permalink
Fixing contract tests + minor fixes in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Apr 5, 2024
1 parent 8155f80 commit f8cc941
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PresenceHeartbeatRequest {
)
request = session.request(
with: PresenceRouter(endpoint, configuration: configuration),
requestOperator: nil
requestOperator: configuration.automaticRetry?.retryOperator(for: .presence)
)
request?.validate().response(on: sessionResponseQueue, decoder: GenericServiceResponseDecoder()) { result in
switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class SubscribeRequest {
private let session: SessionReplaceable
private let sessionResponseQueue: DispatchQueue
private let channelStates: [String: JSONCodable]

private var request: RequestReplaceable?

var retryLimit: UInt { configuration.automaticRetry?.retryLimit ?? 0 }
Expand Down Expand Up @@ -67,7 +66,7 @@ class SubscribeRequest {
)
request = session.request(
with: router,
requestOperator: nil
requestOperator: configuration.automaticRetry?.retryOperator(for: .subscribe)
)
request?.validate().response(
on: sessionResponseQueue,
Expand Down
1 change: 1 addition & 0 deletions Sources/PubNub/Networking/Request/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ final class Request {
delegate.retryResult(for: self, dueTo: error, andPrevious: previousError) { retryResult in
switch retryResult {
case let .success(retryAfter):
self.atomicState.lockedWrite { $0.responesData = nil }
delegate.retryRequest(self, withDelay: retryAfter)
case let .failure(error):
self.finish(error: PubNubError.retry(error, router: self.router))
Expand Down
18 changes: 10 additions & 8 deletions Sources/PubNub/Subscription/SubscriptionSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,21 @@ class SubscriptionSession: EventEmitter, StatusEmitter {
and groups: [String] = [],
presenceOnly: Bool = false
) {
let channelNamesToUnsubscribe = channels.flatMap {
presenceOnly ? [$0.presenceChannelName] : [$0, $0.presenceChannelName]
}
let groupNamesToUnsubscribe = groups.flatMap {
presenceOnly ? [$0.presenceChannelName] : [$0, $0.presenceChannelName]
}
internalUnsubscribe(
from: channels.map { Subscription(queue: queue, entity: channel($0)) },
and: groups.map { Subscription(queue: queue, entity: channelGroup($0)) },
from: globalChannelSubscriptions.compactMap { channelNamesToUnsubscribe.contains($0.key) ? $0.value : nil },
and: globalGroupSubscriptions.compactMap { groupNamesToUnsubscribe.contains($0.key) ? $0.value : nil },
presenceOnly: presenceOnly
)
channels.flatMap {
presenceOnly ? [$0.presenceChannelName] : [$0, $0.presenceChannelName]
}.forEach {
channelNamesToUnsubscribe.forEach {
globalChannelSubscriptions.removeValue(forKey: $0)
}
groups.flatMap {
presenceOnly ? [$0.presenceChannelName] : [$0, $0.presenceChannelName]
}.forEach {
groupNamesToUnsubscribe.forEach {
globalGroupSubscriptions.removeValue(forKey: $0)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class PubNubPresenceEngineContractTestsSteps: PubNubEventEngineContractTestsStep

override func createPubNubClient() -> PubNub {
let container = DependencyContainer(configuration: self.configuration)
let key = PresenceEventEngineDependencyKey.self

self.dispatcherDecorator = DispatcherDecorator(wrappedInstance: EffectDispatcher(
factory: PresenceEffectFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class PubNubSubscribeEngineContractTestsSteps: PubNubEventEngineContractTestsSte

override func createPubNubClient() -> PubNub {
let container = DependencyContainer(configuration: self.configuration)
let key = SubscribeEventEngineDependencyKey.self

self.dispatcherDecorator = DispatcherDecorator(wrappedInstance: EffectDispatcher(
factory: SubscribeEffectFactory(
Expand Down Expand Up @@ -154,8 +153,8 @@ class PubNubSubscribeEngineContractTestsSteps: PubNubEventEngineContractTestsSte
self.subscribeSynchronously(self.client, to: ["test"])
}

When("I subscribe with timetoken 42") { _, _ in
self.subscribeSynchronously(self.client, to: ["test"], timetoken: 42)
When("I subscribe with timetoken 12345678901234567") { _, _ in
self.subscribeSynchronously(self.client, to: ["test"], timetoken: 12345678901234567)
}

Then("I receive an error in my subscribe response") { _, _ in
Expand Down

0 comments on commit f8cc941

Please sign in to comment.