okami.mom/ultraviolet
git clone https://git.nkp.pet/okami.mom/ultraviolet
666ce5e
main
1package uv 2 3import ( 4"runtime" 5"testing" 6) 7 8// TestStopWithInputInFlightDoesNotPanic is the regression test for #177. Stop 9// set t.pr to nil while the input loop could still be about to evaluate it, so 10// the loop dereferenced nil, in ultraviolet's own goroutine where the 11// application cannot recover. 12// 13// each round starts a terminal with a key in flight and stops it at once. 14// there is nothing to assert beyond surviving the rounds. 15// 16// the test pins GOMAXPROCS to 1. with one processor the input loop has not 17// been scheduled by the time Stop returns, so the bug panics in the first 18// round on every run. with several, the loop usually gets to Read first on 19// another processor, and the bug went unseen in every -race run tried. 20func TestStopWithInputInFlightDoesNotPanic (t * testing.T ) { 21defer runtime .GOMAXPROCS (runtime .GOMAXPROCS (1 )) 22 23for i := range 1000 { 24con := newPipeConsole () 25tm := NewTerminal (con ,nil ) 26if err := tm .Start ();err != nil { 27t .Fatalf ("round %d: Start: %v" ,i ,err ) 28 } 29go con .send ("x" ) 30if err := tm .Stop ();err != nil { 31t .Fatalf ("round %d: Stop: %v" ,i ,err ) 32 } 33// with the fix the input loop may still be blocked on the pipe; 34// closing it fails that read and lets the goroutine exit. 35_ = con .feed .Close () 36 } 37}