ollama/progress/progress_test.go
2026-06-18 16:24:43 -07:00

42 lines
709 B
Go

package progress
import (
"bytes"
"sync"
"testing"
)
type progressTestState string
func (s progressTestState) String() string {
return string(s)
}
func TestProgressStopIsIdempotent(t *testing.T) {
var buf bytes.Buffer
p := NewProgress(&buf)
p.Add("one", progressTestState("working"))
if !p.Stop() {
t.Fatal("first stop should report stopped")
}
if p.Stop() {
t.Fatal("second stop should report already stopped")
}
}
func TestProgressConcurrentStopAndClear(t *testing.T) {
var buf bytes.Buffer
p := NewProgress(&buf)
p.Add("one", progressTestState("working"))
var wg sync.WaitGroup
for range 8 {
wg.Add(1)
go func() {
defer wg.Done()
p.StopAndClear()
}()
}
wg.Wait()
}