Skip to content

Commit a36186c

Browse files
test: Updates tests for required sendability conformance
1 parent ccd5f89 commit a36186c

File tree

8 files changed

+36
-36
lines changed

8 files changed

+36
-36
lines changed

Tests/GraphitiTests/HelloWorldTests/HelloWorldAsyncTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ extension HelloResolver {
1919
func subscribeUser(
2020
context _: HelloContext,
2121
arguments _: NoArguments
22-
) -> AsyncThrowingStream<User, Error> {
23-
pubsub.subscribe()
22+
) async -> AsyncThrowingStream<User, Error> {
23+
await pubsub.subscribe()
2424
}
2525

2626
func futureSubscribeUser(
2727
context _: HelloContext,
2828
arguments _: NoArguments
29-
) -> AsyncThrowingStream<User, Error> {
30-
pubsub.subscribe()
29+
) async -> AsyncThrowingStream<User, Error> {
30+
await pubsub.subscribe()
3131
}
3232

3333
func asyncSubscribeUser(
3434
context _: HelloContext,
3535
arguments _: NoArguments
3636
) async -> AsyncThrowingStream<User, Error> {
3737
return await Task {
38-
pubsub.subscribe()
38+
await pubsub.subscribe()
3939
}.value
4040
}
4141
}
@@ -168,7 +168,7 @@ class HelloWorldAsyncTests: XCTestCase {
168168
).get()
169169
var iterator = subscription.makeAsyncIterator()
170170

171-
pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
171+
await pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
172172

173173
let result = try await iterator.next()
174174
XCTAssertEqual(
@@ -201,7 +201,7 @@ class HelloWorldAsyncTests: XCTestCase {
201201
).get()
202202
var iterator = subscription.makeAsyncIterator()
203203

204-
pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
204+
await pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
205205

206206
let result = try await iterator.next()
207207
XCTAssertEqual(
@@ -234,7 +234,7 @@ class HelloWorldAsyncTests: XCTestCase {
234234
).get()
235235
var iterator = subscription.makeAsyncIterator()
236236

237-
pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
237+
await pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
238238

239239
let result = try await iterator.next()
240240
XCTAssertEqual(
@@ -265,7 +265,7 @@ class HelloWorldAsyncTests: XCTestCase {
265265
).get()
266266
var iterator = subscription.makeAsyncIterator()
267267

268-
pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
268+
await pubsub.publish(event: User(id: "124", name: "Jerry", friends: nil))
269269

270270
let result = try await iterator.next()
271271
XCTAssertEqual(
@@ -282,7 +282,7 @@ class HelloWorldAsyncTests: XCTestCase {
282282

283283
/// A very simple publish/subscriber used for testing
284284
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
285-
class SimplePubSub<T> {
285+
actor SimplePubSub<T: Sendable>: Sendable {
286286
private var subscribers: [Subscriber<T>]
287287

288288
init() {
@@ -316,7 +316,7 @@ class SimplePubSub<T> {
316316
}
317317
}
318318

319-
struct Subscriber<T> {
319+
struct Subscriber<T: Sendable> {
320320
let callback: (T) -> Void
321321
let cancel: () -> Void
322322
}

Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct UserEvent {
5656
let user: User
5757
}
5858

59-
final class HelloContext {
59+
final class HelloContext: Sendable {
6060
func hello() -> String {
6161
"world"
6262
}

Tests/GraphitiTests/ScalarTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ class ScalarTests: XCTestCase {
656656
}
657657
}
658658

659-
private class TestAPI<Resolver, ContextType>: API {
659+
private class TestAPI<Resolver: Sendable, ContextType: Sendable>: API {
660660
public let resolver: Resolver
661661
public let schema: Schema<Resolver, ContextType>
662662

Tests/GraphitiTests/SchemaTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class SchemaTests: XCTestCase {
158158
}
159159
}
160160

161-
private class TestAPI<Resolver, ContextType>: API {
161+
private class TestAPI<Resolver: Sendable, ContextType: Sendable>: API {
162162
public let resolver: Resolver
163163
public let schema: Schema<Resolver, ContextType>
164164

Tests/GraphitiTests/StarWarsAPI/StarWarsContext.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* fetching this data from a backend service rather than from hardcoded
66
* values in a more complex demo.
77
*/
8-
public final class StarWarsContext {
9-
private static var tatooine = Planet(
8+
public final class StarWarsContext: Sendable {
9+
private static let tatooine = Planet(
1010
id: "10001",
1111
name: "Tatooine",
1212
diameter: 10465,
@@ -15,7 +15,7 @@ public final class StarWarsContext {
1515
residents: []
1616
)
1717

18-
private static var alderaan = Planet(
18+
private static let alderaan = Planet(
1919
id: "10002",
2020
name: "Alderaan",
2121
diameter: 12500,
@@ -24,76 +24,76 @@ public final class StarWarsContext {
2424
residents: []
2525
)
2626

27-
private static var planetData: [String: Planet] = [
27+
private static let planetData: [String: Planet] = [
2828
"10001": tatooine,
2929
"10002": alderaan,
3030
]
3131

32-
private static var luke = Human(
32+
private static let luke = Human(
3333
id: "1000",
3434
name: "Luke Skywalker",
3535
friends: ["1002", "1003", "2000", "2001"],
3636
appearsIn: [.newHope, .empire, .jedi],
3737
homePlanet: tatooine
3838
)
3939

40-
private static var vader = Human(
40+
private static let vader = Human(
4141
id: "1001",
4242
name: "Darth Vader",
4343
friends: ["1004"],
4444
appearsIn: [.newHope, .empire, .jedi],
4545
homePlanet: tatooine
4646
)
4747

48-
private static var han = Human(
48+
private static let han = Human(
4949
id: "1002",
5050
name: "Han Solo",
5151
friends: ["1000", "1003", "2001"],
5252
appearsIn: [.newHope, .empire, .jedi],
5353
homePlanet: alderaan
5454
)
5555

56-
private static var leia = Human(
56+
private static let leia = Human(
5757
id: "1003",
5858
name: "Leia Organa",
5959
friends: ["1000", "1002", "2000", "2001"],
6060
appearsIn: [.newHope, .empire, .jedi],
6161
homePlanet: alderaan
6262
)
6363

64-
private static var tarkin = Human(
64+
private static let tarkin = Human(
6565
id: "1004",
6666
name: "Wilhuff Tarkin",
6767
friends: ["1001"],
6868
appearsIn: [.newHope],
6969
homePlanet: alderaan
7070
)
7171

72-
private static var humanData: [String: Human] = [
72+
private static let humanData: [String: Human] = [
7373
"1000": luke,
7474
"1001": vader,
7575
"1002": han,
7676
"1003": leia,
7777
"1004": tarkin,
7878
]
7979

80-
private static var c3po = Droid(
80+
private static let c3po = Droid(
8181
id: "2000",
8282
name: "C-3PO",
8383
friends: ["1000", "1002", "1003", "2001"],
8484
appearsIn: [.newHope, .empire, .jedi],
8585
primaryFunction: "Protocol"
8686
)
8787

88-
private static var r2d2 = Droid(
88+
private static let r2d2 = Droid(
8989
id: "2001",
9090
name: "R2-D2",
9191
friends: ["1000", "1002", "1003"],
9292
appearsIn: [.newHope, .empire, .jedi],
9393
primaryFunction: "Astromech"
9494
)
9595

96-
private static var droidData: [String: Droid] = [
96+
private static let droidData: [String: Droid] = [
9797
"2000": c3po,
9898
"2001": r2d2,
9999
]

Tests/GraphitiTests/StarWarsAPI/StarWarsEntities.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
public enum Episode: String, CaseIterable, Codable {
1+
public enum Episode: String, CaseIterable, Codable, Sendable {
22
case newHope = "NEWHOPE"
33
case empire = "EMPIRE"
44
case jedi = "JEDI"
55
}
66

7-
public protocol Character {
7+
public protocol Character: Sendable {
88
var id: String { get }
99
var name: String { get }
1010
var friends: [String] { get }
1111
var appearsIn: [Episode] { get }
1212
}
1313

14-
public protocol SearchResult {}
14+
public protocol SearchResult: Sendable {}
1515

1616
public struct Planet: SearchResult {
1717
public let id: String

Tests/GraphitiTests/StarWarsAPI/StarWarsResolver.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ public extension Droid {
3030
}
3131
}
3232

33-
public struct StarWarsResolver {
33+
public struct StarWarsResolver: Sendable {
3434
public init() {}
3535

36-
public struct HeroArguments: Codable {
36+
public struct HeroArguments: Codable, Sendable {
3737
public let episode: Episode?
3838
}
3939

4040
public func hero(context: StarWarsContext, arguments: HeroArguments) -> Character {
4141
context.getHero(of: arguments.episode)
4242
}
4343

44-
public struct HumanArguments: Codable {
44+
public struct HumanArguments: Codable, Sendable {
4545
public let id: String
4646
}
4747

4848
public func human(context: StarWarsContext, arguments: HumanArguments) -> Human? {
4949
context.getHuman(id: arguments.id)
5050
}
5151

52-
public struct DroidArguments: Codable {
52+
public struct DroidArguments: Codable, Sendable {
5353
public let id: String
5454
}
5555

5656
public func droid(context: StarWarsContext, arguments: DroidArguments) -> Droid? {
5757
context.getDroid(id: arguments.id)
5858
}
5959

60-
public struct SearchArguments: Codable {
60+
public struct SearchArguments: Codable, Sendable {
6161
public let query: String
6262
}
6363

Tests/GraphitiTests/ValidationRulesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ValidationRulesTests: XCTestCase {
4444
}
4545
}
4646

47-
private class TestAPI<Resolver, ContextType>: API {
47+
private class TestAPI<Resolver: Sendable, ContextType: Sendable>: API {
4848
public let resolver: Resolver
4949
public let schema: Schema<Resolver, ContextType>
5050

0 commit comments

Comments
 (0)