Skip to content

Commit 1152a1e

Browse files
committed
Add placement and scheduler in slim mode self-hosted tests
Signed-off-by: Anton Troshin <[email protected]>
1 parent d781b03 commit 1152a1e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/e2e/standalone/commands.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package standalone_test
1818
import (
1919
"context"
2020
"fmt"
21+
"path/filepath"
2122
"strings"
2223

24+
"github.com/dapr/cli/pkg/standalone"
2325
"github.com/dapr/cli/tests/e2e/common"
2426
"github.com/dapr/cli/tests/e2e/spawn"
2527
"github.com/dapr/cli/utils"
@@ -46,6 +48,47 @@ func cmdDashboard(ctx context.Context, port string) error {
4648
return fmt.Errorf("Dashboard could not be started: %s", errOutput)
4749
}
4850

51+
func cmdProcess(ctx context.Context, executable string, log func(args ...any), args ...string) (string, error) {
52+
path, err := GetExecutablePath(executable)
53+
if err != nil {
54+
return "", err
55+
}
56+
57+
stdOutChan, stdErrChan, err := spawn.CommandWithContext(ctx, path, args...)
58+
if err != nil {
59+
return "", err
60+
}
61+
62+
if log != nil {
63+
go func() {
64+
for {
65+
select {
66+
case output := <-stdOutChan:
67+
if output != "" {
68+
log(executable + ": " + output)
69+
}
70+
case output := <-stdErrChan:
71+
if output != "" {
72+
log(executable + ": " + output)
73+
}
74+
case <-ctx.Done():
75+
return
76+
}
77+
}
78+
}()
79+
}
80+
81+
return "", nil
82+
}
83+
84+
func GetExecutablePath(executable string) (string, error) {
85+
path, err := standalone.GetDaprRuntimePath("")
86+
if err != nil {
87+
return "", err
88+
}
89+
return filepath.Join(path, "bin", executable), nil
90+
}
91+
4992
// cmdInit installs Dapr with the init command and returns the command output and error.
5093
//
5194
// When DAPR_E2E_INIT_SLIM is true, it will install Dapr without Docker containers.

tests/e2e/standalone/run_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package standalone_test
1717

1818
import (
19+
"context"
1920
"fmt"
2021
"runtime"
2122
"testing"
@@ -26,9 +27,23 @@ import (
2627

2728
func TestStandaloneRun(t *testing.T) {
2829
ensureDaprInstallation(t)
30+
31+
ctx, cancelFunc := context.WithCancel(context.Background())
32+
defer cancelFunc()
33+
34+
if isSlimMode() {
35+
output, err := cmdProcess(ctx, "placement", t.Log, "--metrics-port", "9091", "--healthz-port", "8081")
36+
require.NoError(t, err)
37+
t.Log(output)
38+
output, err = cmdProcess(ctx, "scheduler", t.Log, "--metrics-port", "9092", "--healthz-port", "8082")
39+
require.NoError(t, err)
40+
t.Log(output)
41+
}
2942
t.Cleanup(func() {
3043
// remove dapr installation after all tests in this function.
3144
must(t, cmdUninstall, "failed to uninstall Dapr")
45+
// Call cancelFunc to stop the processes
46+
cancelFunc()
3247
})
3348
for _, path := range getSocketCases() {
3449
t.Run(fmt.Sprintf("normal exit, socket: %s", path), func(t *testing.T) {

0 commit comments

Comments
 (0)