Skip to content

Commit

Permalink
fix(cardinal): Revert "test(cardinal): Add test samples to cardinal p…
Browse files Browse the repository at this point in the history
…ackage and exte… (Argus-Labs#351)
  • Loading branch information
jerargus committed Oct 25, 2023
1 parent 185efc1 commit e873356
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 496 deletions.
41 changes: 16 additions & 25 deletions cardinal/cardinal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,37 @@ import (
"time"

"gotest.tools/v3/assert"

"pkg.world.dev/world-engine/cardinal"
"pkg.world.dev/world-engine/cardinal/test_utils"
)

func makeWorldAndTicker(t *testing.T) (world *cardinal.World, doTick func()) {
startTickCh, doneTickCh := make(chan time.Time), make(chan uint64)
world, err := cardinal.NewMockWorld(
cardinal.WithTickChannel(startTickCh),
cardinal.WithTickDoneChannel(doneTickCh))
t.Cleanup(func() {
world.ShutDown()
})
assert.NilError(t, err)

return world, func() {
startTickCh <- time.Now()
<-doneTickCh
}
}

type Foo struct{}

func (Foo) Name() string { return "foo" }

func TestCanQueryInsideSystem(t *testing.T) {
test_utils.SetTestTimeout(t, 10*time.Second)

world, doTick := makeWorldAndTicker(t)
nextTickCh := make(chan time.Time)
tickDoneCh := make(chan uint64)

world, err := cardinal.NewMockWorld(
cardinal.WithTickChannel(nextTickCh),
cardinal.WithTickDoneChannel(tickDoneCh))
assert.NilError(t, err)
assert.NilError(t, cardinal.RegisterComponent[Foo](world))

wantNumOfEntities := 10
world.Init(func(worldCtx cardinal.WorldContext) {
_, err := cardinal.CreateMany(worldCtx, wantNumOfEntities, Foo{})
world.Init(func(wCtx cardinal.WorldContext) {
_, err = cardinal.CreateMany(wCtx, wantNumOfEntities, Foo{})
assert.NilError(t, err)
})
gotNumOfEntities := 0
cardinal.RegisterSystems(world, func(worldCtx cardinal.WorldContext) error {
q, err := worldCtx.NewSearch(cardinal.Exact(Foo{}))
cardinal.RegisterSystems(world, func(wCtx cardinal.WorldContext) error {
q, err := wCtx.NewSearch(cardinal.Exact(Foo{}))
assert.NilError(t, err)
err = q.Each(worldCtx, func(cardinal.EntityID) bool {
err = q.Each(wCtx, func(cardinal.EntityID) bool {
gotNumOfEntities++
return true
})
Expand All @@ -57,9 +48,9 @@ func TestCanQueryInsideSystem(t *testing.T) {
for !world.IsGameRunning() {
time.Sleep(time.Second) //starting game async, must wait until game is running before testing everything.
}
doTick()

err := world.ShutDown()
nextTickCh <- time.Now()
<-tickDoneCh
err = world.ShutDown()
assert.Assert(t, err)
assert.Equal(t, gotNumOfEntities, wantNumOfEntities)
}
90 changes: 0 additions & 90 deletions cardinal/component_test.go

This file was deleted.

6 changes: 2 additions & 4 deletions cardinal/ecs/mock_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// NewMockWorld creates an ecs.World that uses a mock redis DB as the storage
// layer. This is only suitable for local development. If you are creating an ecs.World for
// unit tests, use NewTestWorld.
func NewMockWorld(opts ...Option) (world *World, cleanup func()) {
func NewMockWorld(opts ...Option) *World {
// We manually set the start address to make the port deterministic
s := miniredis.NewMiniRedis()
err := s.StartAddr(":12345")
Expand All @@ -30,9 +30,7 @@ func NewMockWorld(opts ...Option) (world *World, cleanup func()) {
panic(fmt.Errorf("unable to initialize world: %w", err))
}

return w, func() {
s.Close()
}
return w
}

// NewTestWorld creates an ecs.World suitable for running in tests. Relevant resources
Expand Down
10 changes: 0 additions & 10 deletions cardinal/evm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Server interface {
routerv1.MsgServer
// Serve serves the application in a new go routine.
Serve() error
Shutdown()
}

// txByID maps transaction type ID's to transaction types.
Expand All @@ -59,8 +58,6 @@ type msgServerImpl struct {
// opts
creds credentials.TransportCredentials
port string

shutdown func()
}

// NewServer returns a new EVM connection server. This server is responsible for handling requests originating from
Expand Down Expand Up @@ -173,16 +170,9 @@ func (s *msgServerImpl) Serve() error {
log.Fatal(err)
}
}()
s.shutdown = server.GracefulStop
return nil
}

func (s *msgServerImpl) Shutdown() {
if s.shutdown != nil {
s.shutdown()
}
}

const (
CodeSuccess = iota
CodeTxFailed
Expand Down
75 changes: 0 additions & 75 deletions cardinal/query_test.go

This file was deleted.

9 changes: 0 additions & 9 deletions cardinal/query.go → cardinal/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,3 @@ func NewQueryTypeWithEVMSupport[Request, Reply any](name string, handler func(Wo
func (r *QueryType[Request, Reply]) Convert() ecs.IQuery {
return r.impl
}

func (q *QueryType[Request, Reply]) DoQuery(worldCtx WorldContext, req Request) (reply Reply, err error) {
iface, err := q.impl.HandleQuery(worldCtx.getECSWorldContext(), req)
if err != nil {
return reply, err
}
reply = iface.(Reply)
return reply, nil
}
82 changes: 0 additions & 82 deletions cardinal/search_test.go

This file was deleted.

Loading

0 comments on commit e873356

Please sign in to comment.