| 1 | package jobs |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "io" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/event" |
| 9 | ) |
| 10 | |
| 11 | // TestOutputSurfacesResultForBufferlessJob probes a task-style job: its run func |
| 12 | // returns a final answer and writes nothing to the streamed buffer (task ignores |
| 13 | // the io.Writer). bash_output reads only the buffer, so once such a job finishes |
| 14 | // its answer is invisible there — yet bash_output's description claims it works |
| 15 | // for task(run_in_background). wait sees the result; bash_output should too. |
| 16 | func TestOutputSurfacesResultForBufferlessJob(t *testing.T) { |
| 17 | m := NewManager(event.Discard) |
| 18 | j := m.Start("task", "demo", func(ctx context.Context, _ io.Writer) (string, error) { |
| 19 | return "THE-ANSWER", nil |
| 20 | }) |
| 21 | <-j.done |
| 22 | |
| 23 | text, status, ok := m.Output(j.ID) |
| 24 | if !ok { |
| 25 | t.Fatal("job not found") |
| 26 | } |
| 27 | if status != Done { |
| 28 | t.Fatalf("status = %q, want done", status) |
| 29 | } |
| 30 | if text == "" { |
| 31 | t.Errorf("bash_output returned no output for a finished task job — its answer %q is invisible", "THE-ANSWER") |
| 32 | } |
| 33 | } |
| 34 |