// COTTON SLOW, walked on dev with a throttled Cotton (FilmSlow.swift; Dev switches only, never the Mac's network): the// featured film's Play while the core gets no answer at first and the relay is slow. The player must say "Cotton is// slow right now · trying again" within a few seconds, keep trying, and play once Cotton answers: never a spinner with// no words, never "could not be played".import XCTestfinalclassCinemasSlowTests: XCTestCase {overridefunc setUp() { continueAfterFailure = false } @MainActor privatefunc element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch } @MainActor privatefunc shot(_ app: XCUIApplication, _ name: String) {let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = name attachment.lifetime = .keepAlways add(attachment) } @MainActor privatefunc play(_ app: XCUIApplication) -> Date {let play = element(app, "cinemas-featured-play") XCTAssertTrue(play.waitForExistence(timeout: 40)) play.tap() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 10), "the player comes up at once")returnDate() }/// Cotton does not answer the first three Play asks, and answers each in 3 s: the words, then the film. @MainActor func testCottonNotAnsweringAtFirst() throws {let app = XCUIApplication() app.launchArguments += ["-film-fail-core", "3", "-film-slow-core-ms", "3000"] app.launch()let tapped = play(app)let slow = element(app, "film-slow") XCTAssertTrue(slow.waitForExistence(timeout: 8), "it says Cotton is slow")let said = Date().timeIntervalSince(tapped)// The shell says the app's own name for Cotton ("Cotton Cinemas is slow right now · trying again"). XCTAssertTrue(slow.label.hasSuffix("is slow right now · trying again"), slow.label) shot(app, "Slow 1 Cotton not answering, \(Int(said)) s after the tap") XCTAssertFalse(app.staticTexts["This film could not be played just now"].exists, "never could not play")// It keeps trying, and plays once Cotton answers: the words go. XCTAssertTrue(slow.waitForNonExistence(timeout: 60), "it played in the end") XCTAssertTrue(element(app, "film-player").exists, "the player stayed up")Thread.sleep(forTimeInterval: 3) shot(app, "Slow 2 playing once Cotton answered") }/// The relay slow (2.5 s before each ask goes, 800 kbit/s): the words while it waits, and the film plays on. @MainActor func testSlowRelay() throws {let app = XCUIApplication() app.launchArguments += ["-film-throttle-ms", "2500", "-film-throttle-kbps", "800"] app.launch()let tapped = play(app)let slow = element(app, "film-slow") XCTAssertTrue(slow.waitForExistence(timeout: 10), "it says Cotton is slow") shot(app, "Slow 3 relay slow, \(Int(Date().timeIntervalSince(tapped))) s after the tap")// Thirty seconds on: the player is still up, trying or playing, never an error.Thread.sleep(forTimeInterval: 30) XCTAssertTrue(element(app, "film-player").exists, "the player stayed up") XCTAssertFalse(app.staticTexts["This film could not be played just now"].exists, "never could not play") shot(app, "Slow 4 relay slow, 30 s on") }}