Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Sep 18, 2023
1 parent e42e56c commit 45c4933
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions base/commands/migration/start_stages_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/base/commands/migration"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/it"
hz "github.com/hazelcast/hazelcast-go-client"
"github.com/hazelcast/hazelcast-go-client/serialization"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -48,7 +47,7 @@ func startTest_Successful(t *testing.T) {
c := make(chan string, 1)
go findMigrationID(ctx, tcx, c)
migrationID := <-c
fileNames := successfulRunner(t, migrationID, tcx, ctx)
migrationReport := successfulRunner(migrationID, tcx, ctx)
wg.Wait()
tcx.AssertStdoutContains(fmt.Sprintf(`
Hazelcast Data Migration Tool v5.3.0
Expand All @@ -63,14 +62,12 @@ first message
second message
last message
status report
migration report saved to file: migration_report_%s
migration report saved to file: migration_report_%s.txt
OK [3/3] Migrated the cluster.
OK Migration completed successfully.`, migrationID))
tcx.WithReset(func() {
for _, n := range fileNames {
require.Equal(t, true, fileExists(n))
}
require.Equal(t, true, fileExists(migrationReport))
})
})
}
Expand All @@ -82,7 +79,7 @@ func startTest_Failure(t *testing.T) {
go tcx.WithReset(func() {
tcx.CLC().Execute(ctx, "start", "dmt-config", "--yes")
})
failureRunner(tcx, ctx)
migrationReport := failureRunner(tcx, ctx)
tcx.AssertStdoutContains(`
Hazelcast Data Migration Tool v5.3.0
(c) 2023 Hazelcast, Inc.
Expand All @@ -95,6 +92,9 @@ first message
OK [2/3] Started the migration.
second message
fail status report`)
tcx.WithReset(func() {
require.Equal(t, true, fileExists(migrationReport))
})
})
}

Expand All @@ -109,14 +109,7 @@ func fileExists(filename string) bool {
return true
}

func successfulRunner(t *testing.T, migrationID string, tcx it.TestContext, ctx context.Context) []string {
var fileNames []string
for _, m := range hz.NewClientInternal(tcx.Client).OrderedMembers() {
l := MustValue(tcx.Client.GetList(ctx, migration.DebugLogsListPrefix+m.UUID.String()))
require.Equal(t, true, MustValue(l.AddAll(ctx, "log1\n", "log2\n", "log3\n")))
fileNames = append(fileNames, fmt.Sprintf("%s%s.log", migration.DebugLogsListPrefix, m.UUID.String()))
}
fileNames = append(fileNames, fmt.Sprintf("migration_report_%s", migrationID))
func successfulRunner(migrationID string, tcx it.TestContext, ctx context.Context) string {
topic := MustValue(tcx.Client.GetTopic(ctx, migration.MakeUpdateTopicName(migrationID)))
msg := MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusInProgress, Message: "first message", CompletionPercentage: 10}))
Must(topic.Publish(ctx, serialization.JSON(msg)))
Expand All @@ -131,10 +124,10 @@ func successfulRunner(t *testing.T, migrationID string, tcx it.TestContext, ctx
Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b)))
msg = MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusComplete, Message: "last message", CompletionPercentage: 100}))
Must(topic.Publish(ctx, serialization.JSON(msg)))
return fileNames
return fmt.Sprintf("migration_report_%s.txt", migrationID)
}

func failureRunner(tcx it.TestContext, ctx context.Context) {
func failureRunner(tcx it.TestContext, ctx context.Context) string {
c := make(chan string, 1)
go findMigrationID(ctx, tcx, c)
migrationID := <-c
Expand All @@ -150,6 +143,7 @@ func failureRunner(tcx it.TestContext, ctx context.Context) {
Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b)))
msg = MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusFailed, Message: "second message", CompletionPercentage: 60}))
Must(topic.Publish(ctx, serialization.JSON(msg)))
return fmt.Sprintf("migration_report_%s.txt", migrationID)
}

func findMigrationID(ctx context.Context, tcx it.TestContext, c chan string) {
Expand Down

0 comments on commit 45c4933

Please sign in to comment.