Skip to content

Commit

Permalink
use test setup in config test with publish, extend sleep for flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Nov 18, 2023
1 parent eb3649b commit d29ff8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
42 changes: 29 additions & 13 deletions Tests/momentoTests/configTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ import XCTest
@testable import momento

final class configTests: XCTestCase {
private var integrationTestCacheName: String!
private var topicClient: TopicClientProtocol!
private var cacheClient: CacheClientProtocol!

override func setUp() async throws {
let testSetup = await setUpIntegrationTests()
self.integrationTestCacheName = testSetup.cacheName
self.topicClient = testSetup.topicClient
self.cacheClient = testSetup.cacheClient
}

override func tearDown() async throws {
await cleanUpIntegrationTests(
cacheName: self.integrationTestCacheName,
cacheClient: self.cacheClient
)
}

func testCreateClientWithDefaultConfig() throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "TEST_AUTH_TOKEN")
Expand All @@ -23,17 +40,16 @@ final class configTests: XCTestCase {
XCTAssertNotNil(client)
}

// func testTimeoutForImpossibleDeadline() async throws {
// let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "TEST_AUTH_TOKEN")
// let configuration = TopicConfigurations.Default.latest().withClientTimeout(timeout: 0.001)
// let client = TopicClient(configuration: configuration, credentialProvider: creds)
// // TODO: use test framework's setup and teardown methods to create and delete caches for use with tests
// let pubResp = await client.publish(
// cacheName: "test-cache",
// topicName: "test-topic",
// value: "test-message"
// )
// XCTAssertTrue(pubResp is TopicPublishError)
// XCTAssertEqual(MomentoErrorCode.TIMEOUT_ERROR, (pubResp as! TopicPublishError).errorCode)
// }
func testTimeoutForImpossibleDeadline() async throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "TEST_AUTH_TOKEN")
let configuration = TopicConfigurations.Default.latest().withClientTimeout(timeout: 0.001)
let topicClient = TopicClient(configuration: configuration, credentialProvider: creds)
let pubResp = await topicClient.publish(
cacheName: self.integrationTestCacheName,
topicName: "test-topic",
value: "test-message"
)
XCTAssertTrue(pubResp is TopicPublishError)
XCTAssertEqual(MomentoErrorCode.TIMEOUT_ERROR, (pubResp as! TopicPublishError).errorCode)
}
}
2 changes: 1 addition & 1 deletion Tests/momentoTests/topicsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final class topicsTests: XCTestCase {
"Unexpected response: \((subResp as! TopicSubscribeError).description)"
)

try await Task.sleep(nanoseconds: 1000)
try await Task.sleep(nanoseconds: 1_000_000_000)
let binaryValue = "publishing and subscribing!".data(using: .utf8)!
let pubResp = await client.publish(
cacheName: "test-cache",
Expand Down

0 comments on commit d29ff8b

Please sign in to comment.