Skip to content

Commit

Permalink
feat: Add initialization timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Dec 11, 2024
1 parent b4586cf commit 957958a
Show file tree
Hide file tree
Showing 26 changed files with 353 additions and 950 deletions.
6 changes: 6 additions & 0 deletions cmd/cartesi-rollups-advancer/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package root

import (
"time"

"github.com/cartesi/rollups-node/internal/advancer"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/spf13/cobra"
Expand All @@ -21,6 +23,7 @@ var (
TelemetryAddress: ":10001",
Impl: &advancerService,
},
MaxStartupTime: 10 * time.Second,
}
)

Expand All @@ -36,6 +39,9 @@ func init() {
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
}

func run(cmd *cobra.Command, args []string) {
Expand Down
6 changes: 6 additions & 0 deletions cmd/cartesi-rollups-claimer/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package root

import (
"time"

"github.com/cartesi/rollups-node/internal/claimer"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/spf13/cobra"
Expand All @@ -24,6 +26,7 @@ var (
Impl: &claimerService,
},
EnableSubmission: true,
MaxStartupTime: 10 * time.Second,
}
)

Expand All @@ -48,6 +51,9 @@ func init() {
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
Cmd.Flags().BoolVar(&createInfo.EnableSubmission,
"claim-submission", createInfo.EnableSubmission,
"enable or disable claim submission (reader mode)")
Expand Down
6 changes: 6 additions & 0 deletions cmd/cartesi-rollups-evm-reader/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package root

import (
"time"

"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/evmreader"
"github.com/cartesi/rollups-node/internal/model"
Expand All @@ -29,6 +31,7 @@ var (
EvmReaderPersistentConfig: model.EvmReaderPersistentConfig{
DefaultBlock: model.DefaultBlockStatusSafe,
},
MaxStartupTime: 10 * time.Second,
}
DefaultBlockString = "safe"
)
Expand Down Expand Up @@ -80,6 +83,9 @@ func init() {
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
}

func run(cmd *cobra.Command, args []string) {
Expand Down
9 changes: 9 additions & 0 deletions cmd/cartesi-rollups-node/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package root

import (
"time"

"github.com/cartesi/rollups-node/internal/node"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/spf13/cobra"
Expand All @@ -23,6 +25,7 @@ var (
TelemetryAddress: ":10001",
Impl: &nodeService,
},
MaxStartupTime: 10 * time.Second,
}
)

Expand All @@ -38,6 +41,12 @@ func init() {
Cmd.Flags().BoolVar(&createInfo.EnableClaimSubmission,
"claim-submission", createInfo.EnableClaimSubmission,
"enable or disable claim submission (reader mode)")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
}

func run(cmd *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cartesi-rollups-validator/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
}

func run(cmd *cobra.Command, args []string) {
cobra.CheckErr(validator.Create(createInfo, &validatorService))
cobra.CheckErr(validator.Create(&createInfo, &validatorService))
validatorService.CreateDefaultHandlers("/" + validatorService.Name)
cobra.CheckErr(validatorService.Serve())
}
12 changes: 1 addition & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ require (
github.com/aws/aws-sdk-go-v2 v1.32.2
github.com/aws/aws-sdk-go-v2/config v1.18.45
github.com/aws/aws-sdk-go-v2/service/kms v1.37.2
github.com/davecgh/go-spew v1.1.1
github.com/deepmap/oapi-codegen/v2 v2.1.0
github.com/golang-migrate/migrate/v4 v4.18.1
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgx v3.6.2+incompatible
github.com/jackc/pgx/v5 v5.7.1
github.com/lmittmann/tint v1.0.5
github.com/mattn/go-isatty v0.0.20
github.com/oapi-codegen/runtime v1.1.1
golang.org/x/sync v0.8.0
golang.org/x/text v0.19.0
Expand All @@ -46,12 +42,12 @@ require (
github.com/aws/smithy-go v1.22.0 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/consensys/bavard v0.1.22 // indirect
github.com/consensys/gnark-crypto v0.14.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
Expand All @@ -61,19 +57,14 @@ require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -86,7 +77,6 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
24 changes: 0 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/esnpM7Geqxka4WSqI1SZc7sMJFd3y4=
Expand Down Expand Up @@ -137,8 +135,6 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
Expand Down Expand Up @@ -179,25 +175,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 h1:vr3AYkKovP8uR8AvSGGUK1IDqRa5lAAvEkZG1LKaCRc=
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=
github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w=
github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc=
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag=
github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o=
github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
Expand Down Expand Up @@ -282,8 +263,6 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand All @@ -296,7 +275,6 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
Expand Down Expand Up @@ -349,7 +327,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -366,7 +343,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down
65 changes: 36 additions & 29 deletions internal/advancer/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/cartesi/rollups-node/internal/advancer/machines"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/services"

"github.com/cartesi/rollups-node/internal/inspect"
. "github.com/cartesi/rollups-node/internal/model"
Expand Down Expand Up @@ -59,6 +60,7 @@ type CreateInfo struct {
HttpPort int
MachineServerVerbosity config.Redacted[cartesimachine.ServerVerbosity]
Machines *machines.Machines
MaxStartupTime time.Duration
}

func (c *CreateInfo) LoadEnv() {
Expand All @@ -69,6 +71,7 @@ func (c *CreateInfo) LoadEnv() {
c.MachineServerVerbosity.Value =
cartesimachine.ServerVerbosity(config.GetMachineServerVerbosity())
c.LogLevel = service.LogLevel(config.GetLogLevel())
c.MaxStartupTime = config.GetMaxStartupTime()
}

func Create(c *CreateInfo, s *Service) error {
Expand All @@ -77,43 +80,47 @@ func Create(c *CreateInfo, s *Service) error {
return err
}

if s.repository == nil {
if c.Repository == nil {
c.Repository, err = repository.Connect(s.Context, c.PostgresEndpoint.Value)
if err != nil {
return err
return service.WithTimeout(c.MaxStartupTime, func() error {
if s.repository == nil {
if c.Repository == nil {
c.Repository, err = repository.Connect(s.Context, c.PostgresEndpoint.Value)
if err != nil {
return err
}
}
s.repository = c.Repository
}
s.repository = c.Repository
}

if s.machines == nil {
if c.Machines == nil {
c.Machines, err = machines.Load(s.Context,
c.Repository, c.MachineServerVerbosity.Value, s.Logger)
if err != nil {
return err
if s.machines == nil {
if c.Machines == nil {
c.Machines, err = machines.Load(s.Context,
c.Repository, c.MachineServerVerbosity.Value, s.Logger)
if err != nil {
return err
}
}
s.machines = c.Machines
}
s.machines = c.Machines
}

// allow partial construction for testing
if c.Machines != nil {
s.inspector = inspect.Inspector{
IInspectMachines: c.Machines,
}
if s.Service.ServeMux == nil {
if c.CreateInfo.ServeMux == nil {
c.ServeMux = http.NewServeMux()
// allow partial construction for testing
if c.Machines != nil {
s.inspector = inspect.Inspector{
IInspectMachines: c.Machines,
}
if s.Service.ServeMux == nil {
if c.CreateInfo.ServeMux == nil {
c.ServeMux = http.NewServeMux()
}
s.ServeMux = c.ServeMux
}
s.ServeMux = c.ServeMux
}
s.ServeMux.Handle("/inspect/{dapp}", http.Handler(&s.inspector))
s.ServeMux.Handle("/inspect/{dapp}/{payload}", http.Handler(&s.inspector))
}

return nil
s.ServeMux.Handle("/inspect/{dapp}",
services.CorsMiddleware(http.Handler(&s.inspector)))
s.ServeMux.Handle("/inspect/{dapp}/{payload}",
services.CorsMiddleware(http.Handler(&s.inspector)))
}
return nil
})
}

func (s *Service) Alive() bool { return true }
Expand Down
9 changes: 6 additions & 3 deletions internal/advancer/advancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
mrand "math/rand"
"testing"
"time"

"github.com/cartesi/rollups-node/internal/advancer/machines"
. "github.com/cartesi/rollups-node/internal/model"
Expand All @@ -26,15 +27,17 @@ func TestAdvancer(t *testing.T) {

type AdvancerSuite struct{ suite.Suite }

func New(m IAdvancerMachines, r IAdvancerRepository) (*Service, error) {
func newMock(m IAdvancerMachines, r IAdvancerRepository) (*Service, error) {
s := &Service{
machines: m,
repository: r,
}
return s, Create(&CreateInfo{
CreateInfo: service.CreateInfo{
Name: "advancer",
Impl: s,
},
MaxStartupTime: 1 * time.Second,
}, s)
}

Expand Down Expand Up @@ -63,7 +66,7 @@ func (s *AdvancerSuite) TestRun() {
},
}

advancer, err := New(machines, repository)
advancer, err := newMock(machines, repository)
require.NotNil(advancer)
require.Nil(err)

Expand All @@ -88,7 +91,7 @@ func (s *AdvancerSuite) TestProcess() {
machines := newMockMachines()
machines.Map[app] = &MockMachine{}
repository := &MockRepository{}
advancer, err := New(machines, repository)
advancer, err := newMock(machines, repository)
require.Nil(err)
return machines, repository, advancer, app
}
Expand Down
Loading

0 comments on commit 957958a

Please sign in to comment.