go: after(d) timer stub + 13 pattern tests → runtime 40/40, Phase 5 closed [shapes-scheduler]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Acceptance bar hit (40 runtime, 497 total). Tests: timer ready, select-with-timeout, fan-in (3 producers), worker queue, pipeline, fan-out-then-fan-in, select source-order, fallback case, default, producer-consumer, two-stage pipeline, channel-counter, after+default, tick-collector. Shape chiselled: timer collapses "after duration" into "channel ready immediately" — select needs only ready? from each case. Real time is when the flip happens, not what the protocol is. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -208,6 +208,104 @@
|
||||
(go-env-lookup env "total"))
|
||||
60)
|
||||
|
||||
(go-rt-test
|
||||
"timer: after(d) returns a ready channel (v0 stub)"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "t := after(100)")))))
|
||||
(go-chan-len (go-env-lookup env "t")))
|
||||
1)
|
||||
|
||||
(go-rt-test
|
||||
"select with timer (after) — buffered value wins, timer is fallback"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func push99(c chan int) { c <- 99 }") (go-parse "c := make()") (go-parse "go push99(c)") (go-parse "t := after(0)") (go-parse "var v = 0") (go-parse "select { case x := <-c: v = x; case y := <-t: v = -1 }")))))
|
||||
(go-env-lookup env "v"))
|
||||
99)
|
||||
|
||||
(go-rt-test
|
||||
"fan-in: 3 producer goroutines, main sums their values"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func send10(c chan int) { c <- 10 }") (go-parse "func send20(c chan int) { c <- 20 }") (go-parse "func send30(c chan int) { c <- 30 }") (go-parse "c := make()") (go-parse "go send10(c)") (go-parse "go send20(c)") (go-parse "go send30(c)") (go-parse "var s = 0") (go-parse "for i := 0; i < 3; i = i + 1 { v := <-c ; s = s + v }")))))
|
||||
(go-env-lookup env "s"))
|
||||
60)
|
||||
|
||||
(go-rt-test
|
||||
"worker queue: range over closed buffered chan drains all jobs"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "jobs := make()") (go-parse "jobs <- 1") (go-parse "jobs <- 2") (go-parse "jobs <- 3") (go-parse "jobs <- 4") (go-parse "close(jobs)") (go-parse "var s = 0") (go-parse "for j := range jobs { s = s + j }")))))
|
||||
(go-env-lookup env "s"))
|
||||
10)
|
||||
|
||||
(go-rt-test
|
||||
"pipeline: stage1 squares, stage2 sums via channels"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func sq(in chan int, out chan int) { for v := range in { out <- v * v } ; close(out) }") (go-parse "in := make()") (go-parse "out := make()") (go-parse "in <- 2") (go-parse "in <- 3") (go-parse "in <- 4") (go-parse "close(in)") (go-parse "go sq(in, out)") (go-parse "var s = 0") (go-parse "for v := range out { s = s + v }")))))
|
||||
(go-env-lookup env "s"))
|
||||
29)
|
||||
|
||||
(go-rt-test
|
||||
"fan-out then fan-in: split job stream across N workers, collect results"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func worker(in chan int, out chan int) { for v := range in { out <- v + 100 } }") (go-parse "jobs := make()") (go-parse "results := make()") (go-parse "jobs <- 1") (go-parse "jobs <- 2") (go-parse "jobs <- 3") (go-parse "close(jobs)") (go-parse "go worker(jobs, results)") (go-parse "close(results)") (go-parse "var s = 0") (go-parse "for r := range results { s = s + r }")))))
|
||||
(go-env-lookup env "s"))
|
||||
306)
|
||||
|
||||
(go-rt-test
|
||||
"select: first ready case wins (channel order = source order)"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "a := make()") (go-parse "b := make()") (go-parse "a <- 1") (go-parse "b <- 2") (go-parse "var v = 0") (go-parse "select { case x := <-a: v = 10; case y := <-b: v = 20 }")))))
|
||||
(go-env-lookup env "v"))
|
||||
10)
|
||||
|
||||
(go-rt-test
|
||||
"select: only second case has a value, that branch executes"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "a := make()") (go-parse "b := make()") (go-parse "b <- 7") (go-parse "var v = 0") (go-parse "select { case x := <-a: v = -1; case y := <-b: v = y }")))))
|
||||
(go-env-lookup env "v"))
|
||||
7)
|
||||
|
||||
(go-rt-test
|
||||
"select with default: no case ready → default fires"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "a := make()") (go-parse "b := make()") (go-parse "var v = 0") (go-parse "select { case x := <-a: v = 1; case y := <-b: v = 2; default: v = 99 }")))))
|
||||
(go-env-lookup env "v"))
|
||||
99)
|
||||
|
||||
(go-rt-test
|
||||
"producer-consumer: one goroutine fills, main drains by count"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func fill5(c chan int) { c <- 1 ; c <- 2 ; c <- 3 ; c <- 4 ; c <- 5 }") (go-parse "c := make()") (go-parse "go fill5(c)") (go-parse "var s = 0") (go-parse "for i := 0; i < 5; i = i + 1 { v := <-c ; s = s + v }")))))
|
||||
(go-env-lookup env "s"))
|
||||
15)
|
||||
|
||||
(go-rt-test
|
||||
"two-stage pipeline: doubler + adder threaded through 3 channels"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func dbl(in chan int, mid chan int) { for v := range in { mid <- v * 2 } ; close(mid) }") (go-parse "func plus1(mid chan int, out chan int) { for v := range mid { out <- v + 1 } ; close(out) }") (go-parse "in := make()") (go-parse "mid := make()") (go-parse "out := make()") (go-parse "in <- 1") (go-parse "in <- 2") (go-parse "in <- 3") (go-parse "close(in)") (go-parse "go dbl(in, mid)") (go-parse "go plus1(mid, out)") (go-parse "var s = 0") (go-parse "for v := range out { s = s + v }")))))
|
||||
(go-env-lookup env "s"))
|
||||
15)
|
||||
|
||||
(go-rt-test
|
||||
"channel as counter: append integers, count buffer size"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func fillN(c chan int, n int) { for i := 0; i < n; i = i + 1 { c <- i } }") (go-parse "c := make()") (go-parse "go fillN(c, 7)")))))
|
||||
(go-chan-len (go-env-lookup env "c")))
|
||||
7)
|
||||
|
||||
(go-rt-test
|
||||
"after(0) + select with default: timer ready, default not taken"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "t := after(0)") (go-parse "var v = 0") (go-parse "select { case x := <-t: v = 7; default: v = -1 }")))))
|
||||
(go-env-lookup env "v"))
|
||||
7)
|
||||
|
||||
(go-rt-test
|
||||
"tick collector: timer + counter accumulates ticks via range count"
|
||||
(let
|
||||
((env (go-eval-program go-env-builtins (list (go-parse "func emitN(c chan int, n int) { for i := 0; i < n; i = i + 1 { c <- 1 } ; close(c) }") (go-parse "ticks := make()") (go-parse "go emitN(ticks, 5)") (go-parse "var total = 0") (go-parse "for t := range ticks { total = total + t }")))))
|
||||
(go-env-lookup env "total"))
|
||||
5)
|
||||
|
||||
(define
|
||||
go-rt-test-summary
|
||||
(str "runtime " go-rt-test-pass "/" go-rt-test-count))
|
||||
|
||||
Reference in New Issue
Block a user