@@ -1476,6 +1476,85 @@ final class ServiceGroupTests: XCTestCase {
14761476 }
14771477 }
14781478
1479+ func testPreambleService( ) async throws {
1480+ struct TestService : Service {
1481+ let continuation : AsyncStream < Int > . Continuation
1482+
1483+ init ( continuation: AsyncStream < Int > . Continuation ) {
1484+ self . continuation = continuation
1485+ }
1486+
1487+ func run( ) async throws {
1488+ continuation. yield ( 1 )
1489+ }
1490+ }
1491+ let ( stream, continuation) = AsyncStream . makeStream ( of: Int . self)
1492+ let preambleService = PreambleService ( service: TestService ( continuation: continuation) ) {
1493+ continuation. yield ( 0 )
1494+ }
1495+ var logger = Logger ( label: " Tests " )
1496+ logger. logLevel = . debug
1497+
1498+ let serviceGroup = ServiceGroup (
1499+ services: [ preambleService] ,
1500+ logger: logger
1501+ )
1502+
1503+ await withThrowingTaskGroup ( of: Void . self) { group in
1504+ group. addTask {
1505+ try await serviceGroup. run ( )
1506+ }
1507+
1508+ var eventIterator = stream. makeAsyncIterator ( )
1509+ await XCTAsyncAssertEqual ( await eventIterator. next ( ) , 0 )
1510+ await XCTAsyncAssertEqual ( await eventIterator. next ( ) , 1 )
1511+
1512+ group. cancelAll ( )
1513+ }
1514+ }
1515+
1516+ func testPreambleServices( ) async throws {
1517+ struct TestService : Service {
1518+ let continuation : AsyncStream < Int > . Continuation
1519+
1520+ init ( continuation: AsyncStream < Int > . Continuation ) {
1521+ self . continuation = continuation
1522+ }
1523+
1524+ func run( ) async throws {
1525+ continuation. yield ( 1 )
1526+ }
1527+ }
1528+ let ( stream, continuation) = AsyncStream . makeStream ( of: Int . self)
1529+ var logger = Logger ( label: " Tests " )
1530+ logger. logLevel = . debug
1531+ let preambleService = PreambleService (
1532+ services: [
1533+ TestService ( continuation: continuation) ,
1534+ TestService ( continuation: continuation) ,
1535+ ] ,
1536+ logger: logger
1537+ ) { continuation. yield ( 0 ) }
1538+
1539+ let serviceGroup = ServiceGroup (
1540+ services: [ preambleService] ,
1541+ logger: logger
1542+ )
1543+
1544+ await withThrowingTaskGroup ( of: Void . self) { group in
1545+ group. addTask {
1546+ try await serviceGroup. run ( )
1547+ }
1548+
1549+ var eventIterator = stream. makeAsyncIterator ( )
1550+ await XCTAsyncAssertEqual ( await eventIterator. next ( ) , 0 )
1551+ await XCTAsyncAssertEqual ( await eventIterator. next ( ) , 1 )
1552+ await XCTAsyncAssertEqual ( await eventIterator. next ( ) , 1 )
1553+
1554+ group. cancelAll ( )
1555+ }
1556+ }
1557+
14791558 // MARK: - Helpers
14801559
14811560 private func makeServiceGroup(
0 commit comments