Skip to content

Commit

Permalink
chore: clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Aug 1, 2024
1 parent 21d930b commit 5005aeb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 65 deletions.
82 changes: 26 additions & 56 deletions internal/cluster/clutser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,34 @@ func createSimulationCluster(nums int) ([]*Cluster, error) {
return result, nil
}

func TestSingleClusterLifetime(t *testing.T) {
clusters, err := createSimulationCluster(1)
if err != nil {
t.Errorf("create simulation cluster failed: %v", err)
return
func launchSimulationCluster(clusters []*Cluster, t *testing.T) {
for _, cluster := range clusters {
cluster.Launch()
}
clusters[0].Launch()
defer func() {
clusters[0].Close()
}

func closeSimulationCluster(clusters []*Cluster, t *testing.T) {
for _, cluster := range clusters {
cluster.Close()
// wait for the cluster to close
time.Sleep(time.Second * 1)
// check if the cluster is closed
_, err := cache.GetMapField[node](CLUSTER_STATUS_HASH_MAP_KEY, clusters[0].id)
_, err := cache.GetMapField[node](CLUSTER_STATUS_HASH_MAP_KEY, cluster.id)
if err == nil {
t.Errorf("cluster is not closed")
return
}
}()
}
}

func TestSingleClusterLifetime(t *testing.T) {
clusters, err := createSimulationCluster(1)
if err != nil {
t.Errorf("create simulation cluster failed: %v", err)
return
}
launchSimulationCluster(clusters, t)
defer closeSimulationCluster(clusters, t)

time.Sleep(time.Second * 1)

Expand All @@ -69,24 +79,10 @@ func TestMultipleClusterLifetime(t *testing.T) {
t.Errorf("create simulation cluster failed: %v", err)
return
}

for _, cluster := range clusters {
cluster.Launch()
defer func(cluster *Cluster) {
cluster.Close()
// wait for the cluster to close
time.Sleep(time.Second * 1)
// check if the cluster is closed
_, err := cache.GetMapField[node](CLUSTER_STATUS_HASH_MAP_KEY, cluster.id)
if err == nil {
t.Errorf("cluster is not closed")
return
}
}(cluster)
}
launchSimulationCluster(clusters, t)
defer closeSimulationCluster(clusters, t)

time.Sleep(time.Second * 1)

has_master := false

for _, cluster := range clusters {
Expand Down Expand Up @@ -117,21 +113,8 @@ func TestClusterSubstituteMaster(t *testing.T) {
t.Errorf("create simulation cluster failed: %v", err)
return
}

for _, cluster := range clusters {
cluster.Launch()
defer func(cluster *Cluster) {
cluster.Close()
// wait for the cluster to close
time.Sleep(time.Second * 1)
// check if the cluster is closed
_, err := cache.GetMapField[node](CLUSTER_STATUS_HASH_MAP_KEY, cluster.id)
if err == nil {
t.Errorf("cluster is not closed")
return
}
}(cluster)
}
launchSimulationCluster(clusters, t)
defer closeSimulationCluster(clusters, t)

time.Sleep(time.Second * 1)

Expand Down Expand Up @@ -184,21 +167,8 @@ func TestClusterAutoGCNoLongerActiveNode(t *testing.T) {
t.Errorf("create simulation cluster failed: %v", err)
return
}

for _, cluster := range clusters {
cluster.Launch()
defer func(cluster *Cluster) {
cluster.Close()
// wait for the cluster to close
time.Sleep(time.Second * 1)
// check if the cluster is closed
_, err := cache.GetMapField[node](CLUSTER_STATUS_HASH_MAP_KEY, cluster.id)
if err == nil {
t.Errorf("cluster is not closed")
return
}
}(cluster)
}
launchSimulationCluster(clusters, t)
defer closeSimulationCluster(clusters, t)

time.Sleep(time.Second * 1)

Expand Down
9 changes: 0 additions & 9 deletions internal/cluster/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,3 @@ func getRandomPluginRuntime() entities.PluginRuntime {
},
}
}

// func TestPluginScheduleLifetime(t *testing.T) {
// plugin := getRandomPluginRuntime()
// cluster, err := createSimulationCluster(1)
// if err != nil {
// t.Errorf("create simulation cluster failed: %v", err)
// return
// }
// }

0 comments on commit 5005aeb

Please sign in to comment.