From 13242029abb7ed5e333461ec095104b36b1bf1c0 Mon Sep 17 00:00:00 2001 From: Nikhilesh Susarla Date: Thu, 16 May 2024 11:11:11 +0530 Subject: [PATCH 1/4] add strict flag for assert --- cmd/serve/serve.go | 4 ++++ internal/util/util.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 6e0df02f..149cf45e 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -184,6 +184,10 @@ func ServeCmd() *cobra.Command { }, } + // assert + cmd.Flags().Bool("strict", true, "strict mode") + _ = viper.BindPFlag("strict", cmd.Flags().Lookup("strict")) + // api cmd.Flags().Int("api-size", 100, "size of the submission queue buffered channel") cmd.Flags().String("api-http-addr", "0.0.0.0:8001", "http server address") diff --git a/internal/util/util.go b/internal/util/util.go index 9c56bd6a..94ba47d1 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -6,10 +6,12 @@ import ( "time" "github.com/robfig/cron/v3" + "github.com/spf13/viper" ) func Assert(cond bool, msg string) { - if !cond { + strict := viper.GetBool("strict") + if strict && !cond { panic(msg) } } From 9aab2cf5cfd06fbcd3fdb3352ad06c020dc22166 Mon Sep 17 00:00:00 2001 From: Nikhilesh Susarla Date: Thu, 16 May 2024 22:37:51 +0530 Subject: [PATCH 2/4] add strict flag in test case for panic --- internal/app/subsystems/aio/store/test/cases.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/app/subsystems/aio/store/test/cases.go b/internal/app/subsystems/aio/store/test/cases.go index 1eb006b8..a2e34f6c 100644 --- a/internal/app/subsystems/aio/store/test/cases.go +++ b/internal/app/subsystems/aio/store/test/cases.go @@ -14,6 +14,7 @@ import ( "github.com/resonatehq/resonate/pkg/schedule" "github.com/resonatehq/resonate/pkg/subscription" "github.com/resonatehq/resonate/pkg/task" + "github.com/spf13/viper" "github.com/resonatehq/resonate/pkg/timeout" "github.com/stretchr/testify/assert" @@ -30,6 +31,8 @@ func (c *testCase) Run(t *testing.T, subsystem aio.Subsystem) { t.Run(c.name, func(t *testing.T) { // assert panic occurs if c.panic { + // set strict to true on panic for assert to panic + viper.Set("strict", true) defer func() { if r := recover(); r == nil { t.Errorf("The function did not panic as expected") From 244e24c7855489ec47d5261843fddf6411ed5b9f Mon Sep 17 00:00:00 2001 From: Nikhilesh Susarla Date: Thu, 16 May 2024 23:04:28 +0530 Subject: [PATCH 3/4] rename strict to ignore-asserts flag --- cmd/serve/serve.go | 4 ++-- internal/app/subsystems/aio/store/test/cases.go | 3 --- internal/util/util.go | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 149cf45e..8e681f06 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -185,8 +185,8 @@ func ServeCmd() *cobra.Command { } // assert - cmd.Flags().Bool("strict", true, "strict mode") - _ = viper.BindPFlag("strict", cmd.Flags().Lookup("strict")) + cmd.Flags().Bool("ignore-asserts", false, "ignore-asserts mode") + _ = viper.BindPFlag("ignore-asserts", cmd.Flags().Lookup("ignore-asserts")) // api cmd.Flags().Int("api-size", 100, "size of the submission queue buffered channel") diff --git a/internal/app/subsystems/aio/store/test/cases.go b/internal/app/subsystems/aio/store/test/cases.go index a2e34f6c..1eb006b8 100644 --- a/internal/app/subsystems/aio/store/test/cases.go +++ b/internal/app/subsystems/aio/store/test/cases.go @@ -14,7 +14,6 @@ import ( "github.com/resonatehq/resonate/pkg/schedule" "github.com/resonatehq/resonate/pkg/subscription" "github.com/resonatehq/resonate/pkg/task" - "github.com/spf13/viper" "github.com/resonatehq/resonate/pkg/timeout" "github.com/stretchr/testify/assert" @@ -31,8 +30,6 @@ func (c *testCase) Run(t *testing.T, subsystem aio.Subsystem) { t.Run(c.name, func(t *testing.T) { // assert panic occurs if c.panic { - // set strict to true on panic for assert to panic - viper.Set("strict", true) defer func() { if r := recover(); r == nil { t.Errorf("The function did not panic as expected") diff --git a/internal/util/util.go b/internal/util/util.go index 94ba47d1..ea0467f0 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -10,8 +10,8 @@ import ( ) func Assert(cond bool, msg string) { - strict := viper.GetBool("strict") - if strict && !cond { + strict := viper.GetBool("ignore-asserts") + if !strict && !cond { panic(msg) } } From 0881abff26c7b10273fab0ad0c4eeb75e9d3e43a Mon Sep 17 00:00:00 2001 From: Nikhilesh Susarla Date: Sat, 18 May 2024 10:58:39 +0530 Subject: [PATCH 4/4] rename var strict to ignoreAsserts --- internal/util/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/util/util.go b/internal/util/util.go index ea0467f0..97c61683 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -10,8 +10,8 @@ import ( ) func Assert(cond bool, msg string) { - strict := viper.GetBool("ignore-asserts") - if !strict && !cond { + ignoreAsserts := viper.GetBool("ignore-asserts") + if !ignoreAsserts && !cond { panic(msg) } }