Skip to content

Commit

Permalink
refactor: enhance metric tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tochemey committed Jan 1, 2024
1 parent 6c299d6 commit b5d0522
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions actors/actor_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"context"
"net"
"os"
"sort"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -1062,6 +1063,23 @@ func TestActorSystem(t *testing.T) {
assert.Len(t, got.ScopeMetrics, 1)
assert.Len(t, got.ScopeMetrics[0].Metrics, 4)

expected := []string{
"actor_child_count",
"actor_stash_count",
"actor_restart_count",
"actors_count",
}
// sort the array
sort.Strings(expected)
// get the metric names
actual := make([]string, len(got.ScopeMetrics[0].Metrics))
for i, metric := range got.ScopeMetrics[0].Metrics {
actual[i] = metric.Name
}
sort.Strings(actual)

assert.ElementsMatch(t, expected, actual)

// stop the actor after some time
time.Sleep(time.Second)

Expand Down
17 changes: 17 additions & 0 deletions actors/pid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package actors
import (
"context"
"os"
"sort"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -1408,6 +1409,22 @@ func TestRegisterMetrics(t *testing.T) {
assert.Len(t, got.ScopeMetrics, 1)
assert.Len(t, got.ScopeMetrics[0].Metrics, 3)

expected := []string{
"actor_child_count",
"actor_stash_count",
"actor_restart_count",
}
// sort the array
sort.Strings(expected)
// get the metric names
actual := make([]string, len(got.ScopeMetrics[0].Metrics))
for i, metric := range got.ScopeMetrics[0].Metrics {
actual[i] = metric.Name
}
sort.Strings(actual)

assert.ElementsMatch(t, expected, actual)

// stop the actor
err = pid.Shutdown(ctx)
assert.NoError(t, err)
Expand Down

0 comments on commit b5d0522

Please sign in to comment.