File: async_test.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,644 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (46 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package llb

import (
	"context"
	"testing"
	"time"

	"github.com/moby/buildkit/solver/pb"
	"github.com/stretchr/testify/require"
)

func TestAsyncNonBlocking(t *testing.T) {
	ctx := context.TODO()

	wait := make(chan struct{})
	ran := make(chan struct{})
	st := Image("alpine").Dir("/foo").Async(func(ctx context.Context, st State, c *Constraints) (State, error) {
		close(ran)
		<-wait // make sure callback doesn't block the chain
		return st.Run(Shlex("cmd1")).Dir("sub"), nil
	}).Run(Shlex("cmd2"))

	close(wait)

	select {
	case <-time.After(100 * time.Millisecond):
	case <-ran:
		require.Fail(t, "callback should not have been called")
	}

	def, err := st.Marshal(ctx)
	require.NoError(t, err)

	m, arr := parseDef(t, def.Def)
	require.Equal(t, 4, len(arr))

	dgst, idx := last(t, arr)
	require.Equal(t, 0, idx)
	require.Equal(t, m[dgst], arr[2])

	require.Equal(t, []string{"cmd1"}, arr[1].Op.(*pb.Op_Exec).Exec.Meta.Args)
	require.Equal(t, "/foo", arr[1].Op.(*pb.Op_Exec).Exec.Meta.Cwd)

	require.Equal(t, []string{"cmd2"}, arr[2].Op.(*pb.Op_Exec).Exec.Meta.Args)
	require.Equal(t, "/foo/sub", arr[2].Op.(*pb.Op_Exec).Exec.Meta.Cwd)
}