MCPcopy
hub / github.com/charmbracelet/bubbletea / TestTeaWaitKill

Function TestTeaWaitKill

tea_test.go:171–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestTeaWaitKill(t *testing.T) {
172 t.Parallel()
173 var buf bytes.Buffer
174 var in bytes.Buffer
175
176 progStarted := make(chan struct{})
177 waitStarted := make(chan struct{})
178 errChan := make(chan error, 1)
179
180 m := &testModel{}
181 p := NewProgram(m,
182 WithInput(&in),
183 WithOutput(&buf),
184 )
185
186 go func() {
187 _, err := p.Run()
188 errChan <- err
189 }()
190
191 go func() {
192 for {
193 time.Sleep(time.Millisecond)
194 if m.executed.Load() != nil {
195 close(progStarted)
196
197 <-waitStarted
198 time.Sleep(50 * time.Millisecond)
199 p.Kill()
200
201 return
202 }
203 }
204 }()
205
206 <-progStarted
207
208 var wg sync.WaitGroup
209 for range 5 {
210 wg.Add(1)
211 go func() {
212 p.Wait()
213 wg.Done()
214 }()
215 }
216 close(waitStarted)
217 wg.Wait()
218
219 err := <-errChan
220 if !errors.Is(err, ErrProgramKilled) {
221 t.Fatalf("Expected %v, got %v", ErrProgramKilled, err)
222 }
223}
224
225func TestTeaWithFilter(t *testing.T) {
226 for _, preventCount := range []uint32{0, 1, 2} {

Callers

nothing calls this directly

Calls 6

RunMethod · 0.95
KillMethod · 0.95
WaitMethod · 0.95
NewProgramFunction · 0.85
WithInputFunction · 0.85
WithOutputFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…