Skip to content

Commit 30d888f

Browse files
JoshVanLartursouza
andauthored
Fix dapr init scheduler (#1428)
* Add E2E to validate scheduler after init. Signed-off-by: Artur Souza <[email protected]> * Adds dapr_scheduler verify container Signed-off-by: joshvanl <[email protected]> * Assert eventually TCP connect Signed-off-by: joshvanl <[email protected]> * Fix eventually t check Signed-off-by: joshvanl <[email protected]> * Write etcd-data-dir to custom path with volume Signed-off-by: joshvanl <[email protected]> * Adds Helpers to test funcs Signed-off-by: joshvanl <[email protected]> * Adds container name to TCP check Signed-off-by: joshvanl <[email protected]> * Use rc.3 for scheduler Signed-off-by: joshvanl <[email protected]> * Print container logs on failed TCP conn Signed-off-by: joshvanl <[email protected]> * Fix params Signed-off-by: joshvanl <[email protected]> * Use b Signed-off-by: joshvanl <[email protected]> * Addfs `dev` flag to rc init Signed-off-by: joshvanl <[email protected]> * Fix version check Signed-off-by: joshvanl <[email protected]> * Skip TCP check on slim mode Signed-off-by: joshvanl <[email protected]> * Remove debug test code Signed-off-by: joshvanl <[email protected]> --------- Signed-off-by: Artur Souza <[email protected]> Signed-off-by: joshvanl <[email protected]> Co-authored-by: Artur Souza <[email protected]>
1 parent 29d29ab commit 30d888f

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

pkg/standalone/standalone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
643643
"--entrypoint", "./scheduler",
644644
}
645645
if info.schedulerVolume != nil {
646-
args = append(args, "--volume", *info.schedulerVolume+":/data-default-dapr-scheduler-server-0")
646+
args = append(args, "--volume", *info.schedulerVolume+":/var/run/dapr/scheduler")
647647
}
648648

649649
if info.dockerNetwork != "" {
@@ -664,7 +664,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
664664
)
665665
}
666666

667-
args = append(args, image)
667+
args = append(args, image, "--etcd-data-dir=/var/run/dapr/scheduler")
668668

669669
_, err = utils.RunCmdAndWait(runtimeCmd, args...)
670670
if err != nil {

tests/e2e/standalone/init_test.go

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ package standalone_test
1818

1919
import (
2020
"context"
21+
"net"
2122
"os"
2223
"path/filepath"
2324
"runtime"
25+
"strconv"
2426
"strings"
2527
"testing"
28+
"time"
2629

30+
"github.com/Masterminds/semver"
2731
"github.com/dapr/cli/tests/e2e/common"
2832
"github.com/dapr/cli/tests/e2e/spawn"
2933
"github.com/docker/docker/api/types"
@@ -157,6 +161,48 @@ func TestStandaloneInit(t *testing.T) {
157161
verifyContainers(t, latestDaprRuntimeVersion)
158162
verifyBinaries(t, daprPath, latestDaprRuntimeVersion, latestDaprDashboardVersion)
159163
verifyConfigs(t, daprPath)
164+
165+
placementPort := 50005
166+
if runtime.GOOS == "windows" {
167+
placementPort = 6050
168+
}
169+
170+
verifyTCPLocalhost(t, placementPort)
171+
})
172+
173+
t.Run("init version with scheduler", func(t *testing.T) {
174+
// Ensure a clean environment
175+
must(t, cmdUninstall, "failed to uninstall Dapr")
176+
177+
args := []string{
178+
"--runtime-version", "1.14.0-rc.3",
179+
"--dev",
180+
}
181+
output, err := cmdInit(args...)
182+
t.Log(output)
183+
require.NoError(t, err, "init failed")
184+
assert.Contains(t, output, "Success! Dapr is up and running.")
185+
186+
homeDir, err := os.UserHomeDir()
187+
require.NoError(t, err, "failed to get user home directory")
188+
189+
daprPath := filepath.Join(homeDir, ".dapr")
190+
require.DirExists(t, daprPath, "Directory %s does not exist", daprPath)
191+
192+
_, latestDaprDashboardVersion := common.GetVersionsFromEnv(t, true)
193+
verifyContainers(t, "1.14.0-rc.3")
194+
verifyBinaries(t, daprPath, "1.14.0-rc.3", latestDaprDashboardVersion)
195+
verifyConfigs(t, daprPath)
196+
197+
placementPort := 50005
198+
schedulerPort := 50006
199+
if runtime.GOOS == "windows" {
200+
placementPort = 6050
201+
schedulerPort = 6060
202+
}
203+
204+
verifyTCPLocalhost(t, placementPort)
205+
verifyTCPLocalhost(t, schedulerPort)
160206
})
161207

162208
t.Run("init without runtime-version flag with mariner images", func(t *testing.T) {
@@ -187,10 +233,11 @@ func TestStandaloneInit(t *testing.T) {
187233
// Note, in case of slim installation, the containers are not installed and
188234
// this test is automatically skipped.
189235
func verifyContainers(t *testing.T, daprRuntimeVersion string) {
236+
t.Helper()
237+
190238
t.Run("verifyContainers", func(t *testing.T) {
191239
if isSlimMode() {
192-
t.Log("Skipping container verification because of slim installation")
193-
return
240+
t.Skip("Skipping container verification because of slim installation")
194241
}
195242

196243
cli, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv)
@@ -205,6 +252,12 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) {
205252
"dapr_redis": "",
206253
}
207254

255+
v, err := semver.NewVersion(daprRuntimeVersion)
256+
require.NoError(t, err)
257+
if v.Major() >= 1 && v.Minor() >= 14 {
258+
daprContainers["dapr_scheduler"] = daprRuntimeVersion
259+
}
260+
208261
for _, container := range containers {
209262
t.Logf("Found container: %v %s %s\n", container.Names, container.Image, container.State)
210263
if container.State != "running" {
@@ -233,6 +286,8 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) {
233286

234287
// verifyBinaries ensures that the correct binaries are present in the correct path.
235288
func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion string) {
289+
t.Helper()
290+
236291
binPath := filepath.Join(daprPath, "bin")
237292
require.DirExists(t, binPath, "Directory %s does not exist", binPath)
238293

@@ -247,6 +302,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str
247302

248303
for bin, version := range binaries {
249304
t.Run("verifyBinaries/"+bin, func(t *testing.T) {
305+
t.Helper()
306+
250307
file := filepath.Join(binPath, bin)
251308
if runtime.GOOS == "windows" {
252309
file += ".exe"
@@ -265,6 +322,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str
265322
// verifyConfigs ensures that the Dapr configuration and component YAMLs
266323
// are present in the correct path and have the correct values.
267324
func verifyConfigs(t *testing.T, daprPath string) {
325+
t.Helper()
326+
268327
configSpec := map[interface{}]interface{}{}
269328
// tracing is not enabled in slim mode by default.
270329
if !isSlimMode() {
@@ -353,3 +412,22 @@ func verifyConfigs(t *testing.T, daprPath string) {
353412
})
354413
}
355414
}
415+
416+
// verifyTCPLocalhost verifies a given localhost TCP port is being listened to.
417+
func verifyTCPLocalhost(t *testing.T, port int) {
418+
t.Helper()
419+
420+
if isSlimMode() {
421+
t.Skip("Skipping container verification because of slim installation")
422+
}
423+
424+
// Check that the server is up and can accept connections.
425+
endpoint := "127.0.0.1:" + strconv.Itoa(port)
426+
assert.EventuallyWithT(t, func(c *assert.CollectT) {
427+
conn, err := net.Dial("tcp", endpoint)
428+
//nolint:testifylint
429+
if assert.NoError(c, err) {
430+
conn.Close()
431+
}
432+
}, time.Second*10, time.Millisecond*10)
433+
}

0 commit comments

Comments
 (0)