Skip to content

Commit 56cc6ff

Browse files
committed
Remove Task.yield workaround
1 parent ccf7cf9 commit 56cc6ff

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

Tests/AppTests/PackageController+routesTests.swift

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,7 @@ import Vapor
619619
}
620620

621621
// test fully qualified route
622-
try await app.test(.GET, "/owner/package/~/documentation/target") { @MainActor res in
623-
await Task.yield() // essential to avoid deadlocking
622+
try await app.test(.GET, "/owner/package/~/documentation/target") { res async in
624623
#expect(res.status == .ok)
625624
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
626625
let body = String(buffer: res.body)
@@ -633,8 +632,7 @@ import Vapor
633632
}
634633

635634
// test catchall
636-
try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { @MainActor res in
637-
await Task.yield() // essential to avoid deadlocking
635+
try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in
638636
#expect(res.status == .ok)
639637
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
640638
let body = String(buffer: res.body)
@@ -648,8 +646,7 @@ import Vapor
648646
}
649647

650648
// Test case insensitive path.
651-
try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { @MainActor res in
652-
await Task.yield() // essential to avoid deadlocking
649+
try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in
653650
#expect(res.status == .ok)
654651
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
655652
let body = String(buffer: res.body)
@@ -699,8 +696,7 @@ import Vapor
699696
// MUT
700697

701698
// test fully qualified route
702-
try await app.test(.GET, "/owner/package/~/documentation/target") { @MainActor res in
703-
await Task.yield() // essential to avoid deadlocking
699+
try await app.test(.GET, "/owner/package/~/documentation/target") { res async in
704700
#expect(res.status == .ok)
705701
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
706702
let body = String(buffer: res.body)
@@ -713,8 +709,7 @@ import Vapor
713709
}
714710

715711
// test catchall
716-
try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { @MainActor res in
717-
await Task.yield() // essential to avoid deadlocking
712+
try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in
718713
#expect(res.status == .ok)
719714
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
720715
let body = String(buffer: res.body)
@@ -727,8 +722,7 @@ import Vapor
727722
}
728723

729724
// Test case insensitive path.
730-
try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { @MainActor res in
731-
await Task.yield() // essential to avoid deadlocking
725+
try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in
732726
#expect(res.status == .ok)
733727
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
734728
let body = String(buffer: res.body)
@@ -782,8 +776,7 @@ import Vapor
782776
}
783777

784778
// test fully qualified route
785-
try await app.test(.GET, "/owner/package/1.2.3/documentation/target") { @MainActor res in
786-
await Task.yield() // essential to avoid deadlocking
779+
try await app.test(.GET, "/owner/package/1.2.3/documentation/target") { res async in
787780
#expect(res.status == .ok)
788781
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
789782
let body = String(buffer: res.body)
@@ -796,8 +789,7 @@ import Vapor
796789
}
797790

798791
// test catchall
799-
try await app.test(.GET, "/owner/package/1.2.3/documentation/target/a/b#anchor") { @MainActor res in
800-
await Task.yield() // essential to avoid deadlocking
792+
try await app.test(.GET, "/owner/package/1.2.3/documentation/target/a/b#anchor") { res async in
801793
#expect(res.status == .ok)
802794
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
803795
let body = String(buffer: res.body)
@@ -810,8 +802,7 @@ import Vapor
810802
}
811803

812804
// Test case insensitive path.
813-
try await app.test(.GET, "/Owner/Package/1.2.3/documentation/target/A/b#Anchor") { @MainActor res in
814-
await Task.yield() // essential to avoid deadlocking
805+
try await app.test(.GET, "/Owner/Package/1.2.3/documentation/target/A/b#Anchor") { res async in
815806
#expect(res.status == .ok)
816807
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
817808
let body = String(buffer: res.body)
@@ -1225,8 +1216,7 @@ import Vapor
12251216
// MUT
12261217

12271218
// test default path
1228-
try await app.test(.GET, "/owner/package/~/documentation/target") { @MainActor res in
1229-
await Task.yield() // essential to avoid deadlocking
1219+
try await app.test(.GET, "/owner/package/~/documentation/target") { res async in
12301220
#expect(res.status == .ok)
12311221
let body = String(buffer: res.body)
12321222
assertSnapshot(of: body, as: .html, named: "current-index")
@@ -1239,8 +1229,7 @@ import Vapor
12391229
}
12401230

12411231
// test reference root path
1242-
try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/target") { @MainActor res in
1243-
await Task.yield() // essential to avoid deadlocking
1232+
try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/target") { res async in
12441233
#expect(res.status == .ok)
12451234
let body = String(buffer: res.body)
12461235
assertSnapshot(of: body, as: .html, named: "ref-index")
@@ -1252,8 +1241,7 @@ import Vapor
12521241
}
12531242

12541243
// test path a/b
1255-
try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/a/b") { @MainActor res in
1256-
await Task.yield() // essential to avoid deadlocking
1244+
try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/a/b") { res async in
12571245
#expect(res.status == .ok)
12581246
#expect(res.content.contentType?.description == "text/html; charset=utf-8")
12591247
let body = String(buffer: res.body)
@@ -1302,16 +1290,13 @@ import Vapor
13021290
try await app.test(.GET, "/owner/package/~/tutorials") { res async in
13031291
#expect(res.status == .notFound)
13041292
}
1305-
try await app.test(.GET, "/owner/package/~/tutorials/foo") { @MainActor res in
1306-
#warning("review if Task.yield() and @MainActor is still needed")
1307-
await Task.yield() // essential to avoid deadlocking
1293+
try await app.test(.GET, "/owner/package/~/tutorials/foo") { res async in
13081294
#expect(res.status == .ok)
13091295
let body = String(buffer: res.body)
13101296
assertSnapshot(of: body, as: .html, named: "index")
13111297
#expect(body.contains(#"var baseUrl = "/owner/package/~/""#))
13121298
}
1313-
try await app.test(.GET, "/owner/package/~/tutorials/foo#anchor") { @MainActor res in
1314-
await Task.yield() // essential to avoid deadlocking
1299+
try await app.test(.GET, "/owner/package/~/tutorials/foo#anchor") { res async in
13151300
#expect(res.status == .ok)
13161301
let body = String(buffer: res.body)
13171302
assertSnapshot(of: body, as: .html, named: "index")
@@ -1572,8 +1557,7 @@ import Vapor
15721557
$0.date.now = .t1 + Constants.branchVersionRefreshDelay + 1
15731558
} operation: {
15741559
// Ensure documentation is resolved
1575-
try await app.test(.GET, "/foo/bar/~/documentation/target") { @MainActor res in
1576-
await Task.yield() // essential to avoid deadlocking
1560+
try await app.test(.GET, "/foo/bar/~/documentation/target") { res async in
15771561
#expect(res.status == .ok)
15781562
assertSnapshot(of: String(buffer: res.body), as: .html, named: "index")
15791563
}
@@ -1586,8 +1570,7 @@ import Vapor
15861570
#expect(commit == ["new-commit"])
15871571

15881572
// Ensure documentation is still being resolved
1589-
try await app.test(.GET, "/foo/bar/~/documentation/target") { @MainActor res in
1590-
await Task.yield() // essential to avoid deadlocking
1573+
try await app.test(.GET, "/foo/bar/~/documentation/target") { res async in
15911574
#expect(res.status == .ok)
15921575
assertSnapshot(of: String(buffer: res.body), as: .html, named: "index")
15931576
}

0 commit comments

Comments
 (0)