File: work_utils.go

package info (click to toggle)
receptor 1.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,772 kB
  • sloc: python: 1,643; makefile: 305; sh: 174
file content (82 lines) | stat: -rw-r--r-- 1,915 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mesh

import (
	"context"
	"fmt"
	"os"
	"path/filepath"
	"testing"
	"time"

	"github.com/ansible/receptor/tests/utils"
)

func workSetup(workPluginName workPlugin, t *testing.T) (map[string]*ReceptorControl, *LibMesh, []byte) {
	checkSkipKube(t)

	m := workTestMesh(workPluginName)

	err := m.Start(t.Name())
	if err != nil {
		t.Fatal(err)
	}

	ctx1, cancel1 := context.WithTimeout(context.Background(), 120*time.Second)
	defer cancel1()

	err = m.WaitForReady(ctx1)
	if err != nil {
		t.Fatal(err, m.DataDir)
	}

	nodes := m.GetNodes()
	controllers := make(map[string]*ReceptorControl)
	for k := range nodes {
		controller := NewReceptorControl()
		err = controller.Connect(nodes[k].GetControlSocket())
		if err != nil {
			t.Fatal(err, m.DataDir)
		}
		controllers[k] = controller
	}

	return controllers, m, []byte("1\n2\n3\n4\n5\n")
}

func assertFilesReleased(ctx context.Context, nodeDir, nodeID, unitID string) error {
	workPath := filepath.Join(nodeDir, "datadir", nodeID, unitID)
	check := func() bool {
		_, err := os.Stat(workPath)

		return os.IsNotExist(err)
	}
	if !utils.CheckUntilTimeout(ctx, 5*time.Second, check) {
		return fmt.Errorf("unitID %s on %s did not release", unitID, nodeID)
	}

	return nil
}

func assertStdoutFizeSize(ctx context.Context, dataDir, nodeID, unitID string, waitUntilSize int) error {
	stdoutFilename := filepath.Join(dataDir, nodeID, unitID, "stdout")
	check := func() bool {
		_, err := os.Stat(stdoutFilename)
		if os.IsNotExist(err) {
			return false
		}
		fstat, _ := os.Stat(stdoutFilename)

		return int(fstat.Size()) >= waitUntilSize
	}
	if !utils.CheckUntilTimeout(ctx, 3000*time.Millisecond, check) {
		return fmt.Errorf("file size not correct for %s", stdoutFilename)
	}

	return nil
}

func checkSkipKube(t *testing.T) {
	if skip := os.Getenv("SKIP_KUBE"); skip == "1" {
		t.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
	}
}