Repository navigation
fix(test): dispatch posted work to the app graph on targets - #563
Conversation
8265ac6 to
b789ea7
Compare
b789ea7 to
84524f2
Compare
1e96e3c to
53896e4
Compare
A step on a target took the engine's barrier as the end of the work, but a posted function that posts another queues it on the test while the barrier runs, and posts handed to the engine did not count as activity, so a chain of posts longer than the quiet time left the step before the last one ran. Count handed posts as activity and keep settling while any are queued after the barrier. App.Post's doc says that fn takes no steps and does not call t.Fatal, as on a target it runs on the engine's goroutine, and the Chinese testing page mirrors the English one. nsgotest keeps a post to the test goroutine for tsxtest (testhost.PostToTest).
Network route functions and host handler promises run in the test's goja VM, which the test goroutine owns. They were posted with nsgotest.App.Post, which now runs its function on the engine's goroutine on a target; post them with testhost.PostToTest instead, which runs on the test goroutine headless and on a target alike.
…hook import The engine's goroutine renders the app, on Windows and Android after Open returns, so the scope App.Post hands work to is set and read under the target's lock, and a post before the platform rendered the app fails the test instead of dereferencing nil. tsx/tsxtest reaches nsgotest's PostToTest hook through internal/testhost, which nsgotest already imports, so the layering test allows that edge and the layers doc names it.
A fake engine goroutine owns the app's graph and runs posts and barriers in order, so the test fails when a posted function runs off the engine or when a step returns before the posts a posted function made have run.
53896e4 to
a2dadc2
Compare
|
Reviewed. Rebased onto current main (now d55b37b, no conflicts at any step) and checked independently; every commit builds and vets after each rebase, and nsgotest, tsxtest, testhost, the press package, moduletest and the root doc tests pass headless on the final head. Code: on a target Fails without the fix:
Verification on the rebased head:
|
Summary
Fixes #549.
App.Post(func() { signal.Set(value) })worked headless but panicked on a target because the test goroutine does not own the real app's reactive graph. On a target,App.Postnow hands its function to the scope the host renders the app under, so it runs on the engine goroutine, and the step's engine barrier waits for it. Internal storage and model callbacks keep running on the test's separate graph on the test goroutine.App.Postuses is set by the engine goroutine (afterOpenreturns on Windows and Android), so it is read and written under the target's lock; a post before the platform rendered the app fails the test with a message instead of a nil dereference.tsx/tsxtestruns its goja VM's work (network route functions, host handler promises) on the test goroutine, which owns the VM. It usedApp.Post, which no longer runs there on a target, so it now uses an unexported hook nsgotest sets ininternal/testhost(PostToTest). The layering test allowstsx/tsxtestto importinternal/testhost, which nsgotest already imports, anddocs/architecture/layers.mdnames the edge.App.Post's doc says which goroutinefnruns on and that it takes no steps and does not callt.Fatal. The English and Chinese testing guides, the architecture testing doc and the skill reference say the same.Targets
nsgotesttarget dispatch; every backend uses the same scope-post path.TestPostsRunOnTheAppGraphon the real target (see Verification).internal/testhost/testdata/presspackage on Linux, macOS, Windows, web and the Android emulator, so the regression runs there without workflow changes.Screenshots
None: graph ownership and test scheduling.
Verification
TestPostsRunOnTheAppGraphfails on main on a real target (Linux under Xvfb:core: the reactive graph belongs to another goroutine; use Scope.Post) and passes with this PR.TestTargetPostsRunOnTheEngineAndSettleWhatTheyPost(nsgotest unit test, fake engine goroutine owning the graph) fails without the settle change (the step ran 13 of 41 chained posts) and passes with it.TestPostsRunOnTheAppGraphandTestPressModifiersReachTheApp: macOS (test binary run on a Mac desktop session), Windows 11 (interactive session), Linux (-target linuxunder Xvfb, whole press package) and web (-target web, whole press package): all passed.go build ./...; vets ofnsgotest,tsx/tsxtestandinternal/testhostfor windows, linux and android/arm64; js/wasm build;go tool nsgo check -target all;go tool nsgo testof./nsgotest,./tsx/tsxtest,./internal/testhost,./internal/testhost/testdata/press,./internal/moduletest,./examples/tsxand-run 'Layer|Skills|Doc' .; the post regressions and target unit tests with-- -race -count=5: all passed. Every commit builds.go tool nsgo test -target macos ./internal/testhost/testdata/presson a Mac desktop passed (10/10), and with main's nsgotest/tsxtestTestPostsRunOnTheAppGraphpanics there with the graph-ownership check, which is the issue's acceptance.Checklist