Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use goakt testing framework #478

Merged
merged 11 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions api/nodecontrol/auction-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"type": "string",
"description": "A one-time identifier used to target deployments"
},
"nexus": {
"type": "string",
"description": "The name of the nexus"
},
"version": {
"type": "string",
"description": "The version of the node"
Expand Down Expand Up @@ -50,7 +46,6 @@
},
"required": [
"bidder_id",
"nexus",
"version",
"uptime",
"target_xkey",
Expand Down
6 changes: 0 additions & 6 deletions api/nodecontrol/gen/auction_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/nex/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/lipgloss v1.0.0 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/deckarep/golang-set/v2 v2.7.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/flowchartsman/retry v1.2.0 // indirect
Expand Down Expand Up @@ -64,7 +65,7 @@ require (
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/redcon v1.6.2 // indirect
github.com/tochemey/goakt/v2 v2.10.2 // indirect
github.com/tochemey/goakt/v2 v2.11.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
Expand All @@ -79,6 +80,6 @@ require (
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
10 changes: 6 additions & 4 deletions cmd/nex/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892/go.mod h1:CTDl0pzVzE5DEzZhPfvhY/9sPFMQIxaJ9VAMs9AagrE=
github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc=
github.com/deckarep/golang-set/v2 v2.7.0 h1:gIloKvD7yH2oip4VLhsv3JyLLFnC0Y2mlusgcvJYW5k=
github.com/deckarep/golang-set/v2 v2.7.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dgryski/go-ddmin v0.0.0-20210904190556-96a6d69f1034/go.mod h1:zz4KxBkcXUWKjIcrc+uphJ1gPh/t18ymGm3PmQ+VGTk=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
Expand Down Expand Up @@ -264,8 +266,8 @@ github.com/tidwall/redcon v1.6.2 h1:5qfvrrybgtO85jnhSravmkZyC0D+7WstbfCs3MmPhow=
github.com/tidwall/redcon v1.6.2/go.mod h1:p5Wbsgeyi2VSTBWOcA5vRXrOb9arFTcU2+ZzFjqV75Y=
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
github.com/tochemey/goakt/v2 v2.10.2 h1:ZR/bqT71sg4jYg+JG2xLPcPX3EH1heOEie3OU5N1nt4=
github.com/tochemey/goakt/v2 v2.10.2/go.mod h1:53SxOqOoPLkg3QxPKShGhmkpUT2JOGAl9hPMIZ+kD1o=
github.com/tochemey/goakt/v2 v2.11.0 h1:4reuqeN8mvsUWu9ecn3Vd+qtpTASj/kEI9W3FRYHofM=
github.com/tochemey/goakt/v2 v2.11.0/go.mod h1:gMba2xHDzLSDojw5m1SPHDzVFgNWn1I6G9zoagym5e0=
github.com/travisjeffery/go-dynaport v1.0.0 h1:m/qqf5AHgB96CMMSworIPyo1i7NZueRsnwdzdCJ8Ajw=
github.com/travisjeffery/go-dynaport v1.0.0/go.mod h1:0LHuDS4QAx+mAc4ri3WkQdavgVoBIZ7cE9ob17KIAJk=
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q=
Expand Down Expand Up @@ -430,8 +432,8 @@ google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ require (
github.com/nats-io/nuid v1.0.1
github.com/opencontainers/image-spec v1.1.0
github.com/stretchr/testify v1.10.0
github.com/tochemey/goakt/v2 v2.10.2
github.com/tochemey/goakt/v2 v2.11.0
golang.org/x/sys v0.28.0
google.golang.org/protobuf v1.36.0
google.golang.org/protobuf v1.36.1
oras.land/oras-go/v2 v2.5.0
)

Expand All @@ -30,6 +30,7 @@ require (
github.com/charmbracelet/lipgloss v1.0.0 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.7.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/flowchartsman/retry v1.2.0 // indirect
github.com/google/btree v1.1.3 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892/go.mod h1:CTDl0pzVzE5DEzZhPfvhY/9sPFMQIxaJ9VAMs9AagrE=
github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc=
github.com/deckarep/golang-set/v2 v2.7.0 h1:gIloKvD7yH2oip4VLhsv3JyLLFnC0Y2mlusgcvJYW5k=
github.com/deckarep/golang-set/v2 v2.7.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dgryski/go-ddmin v0.0.0-20210904190556-96a6d69f1034/go.mod h1:zz4KxBkcXUWKjIcrc+uphJ1gPh/t18ymGm3PmQ+VGTk=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
Expand Down Expand Up @@ -248,8 +250,8 @@ github.com/tidwall/redcon v1.6.2 h1:5qfvrrybgtO85jnhSravmkZyC0D+7WstbfCs3MmPhow=
github.com/tidwall/redcon v1.6.2/go.mod h1:p5Wbsgeyi2VSTBWOcA5vRXrOb9arFTcU2+ZzFjqV75Y=
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
github.com/tochemey/goakt/v2 v2.10.2 h1:ZR/bqT71sg4jYg+JG2xLPcPX3EH1heOEie3OU5N1nt4=
github.com/tochemey/goakt/v2 v2.10.2/go.mod h1:53SxOqOoPLkg3QxPKShGhmkpUT2JOGAl9hPMIZ+kD1o=
github.com/tochemey/goakt/v2 v2.11.0 h1:4reuqeN8mvsUWu9ecn3Vd+qtpTASj/kEI9W3FRYHofM=
github.com/tochemey/goakt/v2 v2.11.0/go.mod h1:gMba2xHDzLSDojw5m1SPHDzVFgNWn1I6G9zoagym5e0=
github.com/travisjeffery/go-dynaport v1.0.0 h1:m/qqf5AHgB96CMMSworIPyo1i7NZueRsnwdzdCJ8Ajw=
github.com/travisjeffery/go-dynaport v1.0.0/go.mod h1:0LHuDS4QAx+mAc4ri3WkQdavgVoBIZ7cE9ob17KIAJk=
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q=
Expand Down Expand Up @@ -412,8 +414,8 @@ google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
6 changes: 3 additions & 3 deletions node/internal/actors/agent_supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package actors

import (
"context"
"io"
"log/slog"

"github.com/tochemey/goakt/v2/goaktpb"
Expand All @@ -16,8 +17,8 @@ const AgentSupervisorActorName = "agent_supervisor"

var _ goakt.Actor = (*AgentSupervisor)(nil)

func CreateAgentSupervisor(system goakt.ActorSystem, options models.NodeOptions) *AgentSupervisor {
return &AgentSupervisor{nodeOptions: options}
func CreateAgentSupervisor(options models.NodeOptions) *AgentSupervisor {
return &AgentSupervisor{logger: slog.New(slog.NewTextHandler(io.Discard, nil)), nodeOptions: options}
}

// Agent manager is responsible for starting one agent per workload type, supplying it with
Expand All @@ -30,7 +31,6 @@ type AgentSupervisor struct {
}

func (s *AgentSupervisor) PreStart(ctx context.Context) error {

return nil
}

Expand Down
50 changes: 50 additions & 0 deletions node/internal/actors/agent_supervisor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package actors

import (
"context"
"io"
"log/slog"
"testing"
"time"

"github.com/synadia-io/nex/models"
actorproto "github.com/synadia-io/nex/node/internal/actors/pb"

"github.com/tochemey/goakt/v2/testkit"
)

func TestAgentSupervisor(t *testing.T) {
ctx := context.Background()

as := &AgentSupervisor{
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
nodeOptions: models.NodeOptions{},
}

tk := testkit.New(ctx, t)
t.Run("Send QueryWorkloads Message", func(t *testing.T) {
tk.Spawn(ctx, AgentSupervisorActorName, as)
probe := tk.NewProbe(ctx)
msg := new(actorproto.QueryWorkloads)
probe.SendSync(AgentSupervisorActorName, msg, time.Second)
resp := &actorproto.WorkloadList{
Workloads: []*actorproto.WorkloadSummary{},
}
probe.ExpectMessage(resp)
probe.ExpectNoMessage()
probe.Stop()
})

t.Run("Send SetLameDuck Message", func(t *testing.T) {
tk.Spawn(ctx, AgentSupervisorActorName, as)
probe := tk.NewProbe(ctx)
msg := new(actorproto.SetLameDuck)
probe.Send(AgentSupervisorActorName, msg)
probe.ExpectNoMessage()
probe.Stop()
})

t.Cleanup(func() {
tk.Shutdown(ctx)
})
}
30 changes: 11 additions & 19 deletions node/internal/actors/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ import (
"testing"
"time"

"github.com/carlmjohnson/be"
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
)

func startNatsServer(t testing.TB) (*server.Server, error) {
func startNatsServer(t testing.TB, workingDir string) *server.Server {
t.Helper()

s, err := server.NewServer(&server.Options{
Port: -1,
JetStream: true,
StoreDir: workingDir,
})

if err != nil {
return nil, err
}
be.NilErr(t, err)

go func() {
if err := server.Run(s); err != nil {
Expand All @@ -40,22 +39,18 @@ func startNatsServer(t testing.TB) (*server.Server, error) {
time.Sleep(1 * time.Second)

nc, err := nats.Connect(s.ClientURL())
if err != nil {
return nil, err
}
be.NilErr(t, err)

jsCtx, err := jetstream.New(nc)
if err != nil {
return nil, err
}
be.NilErr(t, err)

_, err = jsCtx.CreateKeyValue(context.TODO(), jetstream.KeyValueConfig{
Bucket: "registry",
})
if err != nil {
return nil, err
}
be.NilErr(t, err)
nc.Close()

return s, nil
return s
}

func createTestBinary(t testing.TB, tmpDir string) (string, string, int) {
Expand Down Expand Up @@ -102,10 +97,7 @@ func createTestBinary(t testing.TB, tmpDir string) (string, string, int) {
}

func prepNatsObjStoreArtifact(t testing.TB, workingDir, binPath string) (string, *nats.Conn, error) {
s, err := startNatsServer(t)
if err != nil {
return "", nil, err
}
s := startNatsServer(t, t.TempDir())

nc, err := nats.Connect(s.ClientURL())
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion node/internal/actors/control_api_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func auctionResponseFromProto(response *actorproto.AuctionResponse) *api.Auction
}

return &api.AuctionResponseJson{
Nexus: response.Nexus,
BidderId: response.BidderId,
Status: gen.AuctionResponseJsonStatus{Status: convertedStatus},
Tags: api.AuctionResponseJsonTags{Tags: response.Tags},
Expand Down
Loading
Loading