Fix RelayPool tests and re-add to target

Restore RelayPoolTests to damusTests after 9091cb1a removed it
from the Xcode test target unintentionally.

Update its add-relay checks for the current async RelayPool API.

Signed-off-by: Sjors Provoost <sjors@sprovoost.nl>
This commit is contained in:
Sjors Provoost
2026-05-26 11:07:07 +02:00
parent 5920d00bb3
commit 8c5b514057
2 changed files with 30 additions and 20 deletions
+26 -20
View File
@@ -18,45 +18,51 @@ final class RelayPoolTests: XCTestCase {
override func tearDownWithError() throws {
}
func testAddRelay_ValidRelayURL_NoErrors() {
testAddRelays(urls: [
@MainActor
func testAddRelay_ValidRelayURL_NoErrors() async {
await testAddRelays(urls: [
"wss://relay.damus.io"
])
}
func testAddRelay_TwoSameURLs_ThrowsRelayAlreadyExists() {
testAddRelays(urls: [
@MainActor
func testAddRelay_TwoSameURLs_ThrowsRelayAlreadyExists() async {
await testAddRelays(urls: [
"wss://relay.damus.io",
"wss://relay.damus.io"
], expectedError: .RelayAlreadyExists)
}
func testAddRelay_OneExtraneousSlashURL_ThrowsRelayAlreadyExists() {
testAddRelays(urls: [
@MainActor
func testAddRelay_OneExtraneousSlashURL_ThrowsRelayAlreadyExists() async {
await testAddRelays(urls: [
"wss://relay.damus.io",
"wss://relay.damus.io/"
], expectedError: .RelayAlreadyExists)
}
func testAddRelay_MultipleExtraneousSlashURL_ThrowsRelayAlreadyExists() {
testAddRelays(urls: [
@MainActor
func testAddRelay_MultipleExtraneousSlashURL_ThrowsRelayAlreadyExists() async {
await testAddRelays(urls: [
"wss://relay.damus.io",
"wss://relay.damus.io///"
], expectedError: .RelayAlreadyExists)
}
func testAddRelay_ExtraSlashURLFirst_ThrowsRelayAlreadyExists() {
testAddRelays(urls: [
@MainActor
func testAddRelay_ExtraSlashURLFirst_ThrowsRelayAlreadyExists() async {
await testAddRelays(urls: [
"wss://relay.damus.io///",
"wss://relay.damus.io"
], expectedError: .RelayAlreadyExists)
}
}
func testAddRelays(urls: [String], expectedError: RelayError? = nil) {
let ndb = Ndb()!
let relayPool = RelayPool(ndb: ndb)
let info = RelayInfo(read: true, write: true)
/// Adds relay URLs to a pool and verifies duplicate URL handling.
@MainActor
func testAddRelays(urls: [String], expectedError: RelayPool.RelayError? = nil) async {
let relayPool = RelayPool(ndb: nil)
do {
for relay in urls {
@@ -65,14 +71,14 @@ func testAddRelays(urls: [String], expectedError: RelayError? = nil) {
return
}
let descriptor = RelayDescriptor(url: url, info: info)
try relayPool.add_relay(descriptor)
let descriptor = RelayPool.RelayDescriptor(url: url, info: .readWrite)
try await relayPool.add_relay(descriptor)
}
if expectedError != nil {
XCTFail("Expected \(expectedError!) error, but no error was thrown.")
}
} catch let error as RelayError where expectedError == .RelayAlreadyExists {
} catch let error as RelayPool.RelayError where expectedError == .RelayAlreadyExists {
XCTAssertEqual(error, expectedError!, "Expected RelayAlreadyExists error, got \(error)")
} catch {
XCTFail("An unexpected error was thrown: \(error)")