Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:
xcodebuild -resolvePackageDependencies -workspace swiftchan.xcodeproj/project.xcworkspace -scheme swiftchan -clonedSourcePackagesDirPath build/SourcePackages -onlyUsePackageVersionsFromResolvedFile

- name: Build and test
run: bundle exec fastlane tests
timeout-minutes: 20
run: bash ci_scripts/test_with_diagnostics.sh
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

- name: Upload test results
if: always()
Expand Down
19 changes: 19 additions & 0 deletions ci_scripts/test_with_diagnostics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail

# XCTest's timeout often omits the app's blocked stack. Capture it while the app is alive.
bundle exec fastlane tests &
test_pid=$!
(
while kill -0 "$test_pid" 2>/dev/null; do
sleep 60
for app_pid in $(pgrep -x swiftchan || true); do
output_dir="fastlane/test_output/main-thread-samples"
mkdir -p "$output_dir"
sample "$app_pid" 1 -file "$output_dir/$app_pid-$(date +%s).txt" >/dev/null 2>&1 || true
done
done
) &
monitor_pid=$!
trap 'kill "$monitor_pid" 2>/dev/null || true' EXIT
wait "$test_pid"
15 changes: 8 additions & 7 deletions swiftchan/Views/Boards/Catalog/Thread/ThreadAutoRefresher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import Combine
class ThreadAutoRefresher {
private(set) var secondsRemaining: Int = 0
var pauseAutoRefresh: Bool = false
var isActive: Bool = true
var isActive: Bool = false

private var timerCancellable: AnyCancellable?
private var cachedRefreshEnabled: Bool = false
private var cachedRefreshTime: Int = 10
@ObservationIgnored private var timerCancellable: AnyCancellable?
@ObservationIgnored private var cachedRefreshEnabled: Bool = false
@ObservationIgnored private var cachedRefreshTime: Int = 10

var onRefresh: (() -> Void)?
@ObservationIgnored var onRefresh: (() -> Void)?

init() {
updateCachedSettings()
resetTimer()
startTimer()
}

deinit {
cancelTimer()
// SwiftUI discards temporary State initial values during body evaluation.
// Deinitialization must not invalidate that evaluation through Observation.
timerCancellable?.cancel()
}

func updateCachedSettings() {
Expand Down
15 changes: 15 additions & 0 deletions swiftchanTests/ThreadViewModelTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import XCTest
import FourChan
import Observation
@testable import swiftchan

@MainActor
final class ThreadViewModelTests: XCTestCase {
func testDiscardingTemporaryRefresherDoesNotInvalidatePresentingView() {
let invalidation = expectation(description: "Temporary timer does not invalidate view construction")
invalidation.isInverted = true
var refresher: ThreadAutoRefresher? = withObservationTracking {
ThreadAutoRefresher()
} onChange: {
invalidation.fulfill()
}
XCTAssertNotNil(refresher)
XCTAssertFalse(refresher?.isActive ?? true)
refresher = nil
wait(for: [invalidation], timeout: 0.05)
}

func testSharedPostLinkPreservesBoardThreadAndExactReply() {
let model = ThreadViewModel(boardName: "biz", id: 100)
XCTAssertEqual(model.postURL(105).absoluteString, "https://boards.4chan.org/biz/thread/100#p105")
Expand Down