Skip to content

Commit

Permalink
get the tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 21, 2025
1 parent 4e99f74 commit a6d20db
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 21 deletions.
12 changes: 6 additions & 6 deletions Tests/XMTPTests/ConversationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class ConversationTests: XCTestCase {
let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)

let sameDm = try await fixtures.boClient.findConversationByTopic(
let sameDm = try await fixtures.boClient.conversations.findConversationByTopic(
topic: dm.topic)
let sameGroup = try await fixtures.boClient.findConversationByTopic(
let sameGroup = try await fixtures.boClient.conversations.findConversationByTopic(
topic: group.topic)

XCTAssertEqual(group.id, sameGroup?.id)
Expand Down Expand Up @@ -236,11 +236,11 @@ class ConversationTests: XCTestCase {
_ = try await fixtures.caroClient.conversations.syncAllConversations()
_ = try await fixtures.boClient.conversations.syncAllConversations()

let boGroup = try fixtures.boClient.findGroup(groupId: alixGroup.id)!
let caroGroup = try fixtures.caroClient.findGroup(
let boGroup = try await fixtures.boClient.conversations.findGroup(groupId: alixGroup.id)!
let caroGroup = try await fixtures.caroClient.conversations.findGroup(
groupId: alixGroup.id)!
let boGroup2 = try fixtures.boClient.findGroup(groupId: caroGroup2.id)!
let alixGroup2 = try fixtures.alixClient.findGroup(
let boGroup2 = try await fixtures.boClient.conversations.findGroup(groupId: caroGroup2.id)!
let alixGroup2 = try await fixtures.alixClient.conversations.findGroup(
groupId: caroGroup2.id)!

// Start listening for messages
Expand Down
10 changes: 5 additions & 5 deletions Tests/XMTPTests/DmTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class DmTests: XCTestCase {
let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)

let caroDm = try fixtures.boClient.findDmByInboxId(
let caroDm = try await fixtures.boClient.conversations.findDmByInboxId(
inboxId: fixtures.caroClient.inboxID)
let alixDm = try fixtures.boClient.findDmByInboxId(
let alixDm = try await fixtures.boClient.conversations.findDmByInboxId(
inboxId: fixtures.alixClient.inboxID)

XCTAssertNil(alixDm)
Expand All @@ -28,9 +28,9 @@ class DmTests: XCTestCase {
let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)

let caroDm = try await fixtures.boClient.findDmByAddress(
let caroDm = try await fixtures.boClient.conversations.findDmByAddress(
address: fixtures.caroClient.address)
let alixDm = try await fixtures.boClient.findDmByAddress(
let alixDm = try await fixtures.boClient.conversations.findDmByAddress(
address: fixtures.alixClient.address)

XCTAssertNil(alixDm)
Expand Down Expand Up @@ -300,7 +300,7 @@ class DmTests: XCTestCase {
_ = try await boDm.send(content: "howdy")
_ = try await fixtures.alixClient.conversations.syncAllConversations()

let alixDm = try fixtures.alixClient.findDmByInboxId(inboxId: fixtures.boClient.inboxID)
let alixDm = try await fixtures.alixClient.conversations.findDmByInboxId(inboxId: fixtures.boClient.inboxID)

let boGroupMessagesCount = try await boDm.messages().count
let alixGroupMessagesCount = try await alixDm?.messages().count
Expand Down
14 changes: 7 additions & 7 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ class GroupTests: XCTestCase {
XCTAssertEqual(groupImageUrlSquare, "newurl.com")

try await fixtures.boClient.conversations.sync()
let boGroup = try fixtures.boClient.findGroup(groupId: group.id)!
let boGroup = try await fixtures.boClient.conversations.findGroup(groupId: group.id)!
groupName = try boGroup.groupName()
XCTAssertEqual(groupName, "Start Name")

Expand Down Expand Up @@ -913,7 +913,7 @@ class GroupTests: XCTestCase {
let boGroup = try await fixtures.boClient.conversations.newGroup(
with: [fixtures.alix.address])
try await fixtures.alixClient.conversations.sync()
let alixGroup = try fixtures.alixClient.findGroup(groupId: boGroup.id)
let alixGroup = try await fixtures.alixClient.conversations.findGroup(groupId: boGroup.id)

XCTAssertEqual(alixGroup?.id, boGroup.id)
}
Expand All @@ -926,9 +926,9 @@ class GroupTests: XCTestCase {

let boMessageId = try await boGroup.send(content: "Hello")
try await fixtures.alixClient.conversations.sync()
let alixGroup = try fixtures.alixClient.findGroup(groupId: boGroup.id)
let alixGroup = try await fixtures.alixClient.conversations.findGroup(groupId: boGroup.id)
try await alixGroup?.sync()
_ = try fixtures.alixClient.findMessage(messageId: boMessageId)
_ = try await fixtures.alixClient.conversations.findMessage(messageId: boMessageId)

XCTAssertEqual(alixGroup?.id, boGroup.id)
}
Expand All @@ -939,7 +939,7 @@ class GroupTests: XCTestCase {
with: [fixtures.alix.address])

try await fixtures.alixClient.conversations.sync()
let alixGroup = try fixtures.alixClient.findGroup(groupId: boGroup.id)!
let alixGroup = try await fixtures.alixClient.conversations.findGroup(groupId: boGroup.id)!
let isGroupAllowed = try await fixtures.alixClient.preferences
.conversationState(conversationId: boGroup.id)
XCTAssertEqual(isGroupAllowed, .unknown)
Expand Down Expand Up @@ -989,7 +989,7 @@ class GroupTests: XCTestCase {
groups.append(group)
}
try await fixtures.boClient.conversations.sync()
let boGroup = try fixtures.boClient.findGroup(groupId: groups[0].id)
let boGroup = try await fixtures.boClient.conversations.findGroup(groupId: groups[0].id)
_ = try await groups[0].send(content: "hi")
let messageCount = try await boGroup!.messages().count
XCTAssertEqual(messageCount, 0)
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class GroupTests: XCTestCase {
_ = try await boGroup.send(content: "howdy")
_ = try await fixtures.alixClient.conversations.syncAllConversations()

let alixGroup = try fixtures.alixClient.findGroup(
let alixGroup = try await fixtures.alixClient.conversations.findGroup(
groupId: boGroup.id)

let boGroupMessagesCount = try await boGroup.messages().count
Expand Down
6 changes: 3 additions & 3 deletions Tests/XMTPTests/HistorySyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HistorySyncTests: XCTestCase {
try await alixClient2.conversations.syncAllConversations()
sleep(2)

if let dm2 = try await alixClient2.findConversation(
if let dm2 = try await alixClient2.conversations.findConversation(
conversationId: group.id)
{
XCTAssertEqual(try dm2.consentState(), .denied)
Expand Down Expand Up @@ -116,7 +116,7 @@ class HistorySyncTests: XCTestCase {
try await alixClient2.conversations.syncAllConversations()
sleep(2)

if let group2 = try await alixClient2.findGroup(
if let group2 = try await alixClient2.conversations.findGroup(
groupId: group.id)
{
let messageCount2 = try await group2.messages().count
Expand Down Expand Up @@ -159,7 +159,7 @@ class HistorySyncTests: XCTestCase {
try await alixGroup.send(content: "Hello")
try await alixClient.conversations.syncAllConversations()
try await alixClient2.conversations.syncAllConversations()
let alixGroup2 = try alixClient2.findGroup(groupId: alixGroup.id)!
let alixGroup2 = try await alixClient2.conversations.findGroup(groupId: alixGroup.id)!

var consentList = [ConsentRecord]()
let expectation = XCTestExpectation(description: "Stream Consent")
Expand Down
141 changes: 141 additions & 0 deletions Tests/XMTPTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,147 @@ import XMTPTestHelpers

@available(iOS 15, *)
class PerformanceTests: XCTestCase {
static var dm: Dm?
static var group: Group?

func test1_CreateDM() async throws {
let fixtures = try await fixtures(
clientOptions: ClientOptions.Api(
env: XMTPEnvironment.dev, isSecure: true))

measure {
let expectation = expectation(description: "Async create DM")
let startTime = CFAbsoluteTimeGetCurrent()

Task {
do {
PerformanceTests.dm = try await fixtures.alixClient
.conversations.findOrCreateDm(
with: fixtures.boClient.address)

let elapsedTime =
(CFAbsoluteTimeGetCurrent() - startTime) * 1000
print("test1_CreateDM execution time: \(elapsedTime) ms")
XCTAssertLessThanOrEqual(
elapsedTime, 500, "CreateDM took too long!")

expectation.fulfill()
} catch {
XCTFail("Failed to create DM: \(error)")
}
}
wait(for: [expectation], timeout: 10)
}

XCTAssertNotNil(PerformanceTests.dm)
}

func test2_SendGm() async throws {
let fixtures = try await fixtures(
clientOptions: ClientOptions.Api(
env: XMTPEnvironment.dev, isSecure: true))

guard let dm = PerformanceTests.dm else {
XCTFail("DM is nil")
return
}
let gmMessage = "gm-\(Int.random(in: 1...999999))"

measure {
let expectation = expectation(description: "Async send GM")
let startTime = CFAbsoluteTimeGetCurrent()

Task {
do {
_ = try await dm.send(content: gmMessage)

let elapsedTime =
(CFAbsoluteTimeGetCurrent() - startTime) * 1000
print("test2_SendGm execution time: \(elapsedTime) ms")
XCTAssertLessThanOrEqual(
elapsedTime, 500, "SendGM took too long!")

expectation.fulfill()
} catch {
XCTFail("Failed to send GM: \(error)")
}
}
wait(for: [expectation], timeout: 10)
}
}

func test3_CreateGroup() async throws {
let fixtures = try await fixtures(
clientOptions: ClientOptions.Api(
env: XMTPEnvironment.dev, isSecure: true))

measure {
let expectation = expectation(description: "Async create group")
let startTime = CFAbsoluteTimeGetCurrent()

Task {
do {
PerformanceTests.group = try await fixtures.alixClient
.conversations.newGroup(
with: [
fixtures.boClient.address,
fixtures.caroClient.address,
fixtures.davonClient.address,
]
)

let elapsedTime =
(CFAbsoluteTimeGetCurrent() - startTime) * 1000
print("test3_CreateGroup execution time: \(elapsedTime) ms")
XCTAssertLessThanOrEqual(
elapsedTime, 500, "CreateGroup took too long!")

expectation.fulfill()
} catch {
XCTFail("Failed to create group: \(error)")
}
}
wait(for: [expectation], timeout: 10)
}

XCTAssertNotNil(PerformanceTests.group)
}

func test4_SendGmInGroup() async throws {
let fixtures = try await fixtures(
clientOptions: ClientOptions.Api(
env: XMTPEnvironment.dev, isSecure: true))

guard let group = PerformanceTests.group else {
XCTFail("Group is nil")
return
}
let groupMessage = "gm-\(Int.random(in: 1...999999))"

measure {
let expectation = expectation(description: "Async send GM in group")
let startTime = CFAbsoluteTimeGetCurrent()

Task {
do {
_ = try await group.send(content: groupMessage)

let elapsedTime =
(CFAbsoluteTimeGetCurrent() - startTime) * 1000
print(
"test4_SendGmInGroup execution time: \(elapsedTime) ms")
XCTAssertLessThanOrEqual(
elapsedTime, 500, "SendGmInGroup took too long!")

expectation.fulfill()
} catch {
XCTFail("Failed to send GM in group: \(error)")
}
}
wait(for: [expectation], timeout: 10)
}
}

func testCreatesADevClientPerformance() async throws {
let key = try Crypto.secureRandomBytes(count: 32)
let fakeWallet = try PrivateKey.generate()
Expand Down

0 comments on commit a6d20db

Please sign in to comment.