Skip to content

Commit

Permalink
Merge pull request #60 from kaleido-io/evt-polling
Browse files Browse the repository at this point in the history
Update default event polling interval from 10sec to 1sec
  • Loading branch information
peterbroadhurst authored Dec 20, 2021
2 parents d601efb + 4ecbede commit 166f927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions cmd/fabconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestMain(m *testing.M) {
func setup() {
tmpdir, testConfig = test.Setup()
os.Setenv("FC_HTTP_PORT", "8002")
os.Setenv("FC_EVENTS_POLLINGINTERVAL", "60")
os.Setenv("FC_MAXINFLIGHT", "60")
}

func teardown() {
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestBadConfigFile(t *testing.T) {
}
rootCmd.SetArgs(args)
err := rootCmd.Execute()
assert.Regexp(regexp.MustCompile(`cannot parse 'maxInFlight' as int`), err)
assert.Regexp(regexp.MustCompile(`User credentials store creation failed`), err)
}

func TestStartServerError(t *testing.T) {
Expand Down Expand Up @@ -103,6 +103,7 @@ func TestMaxWaitTimeTooSmallWarns(t *testing.T) {
err := rootCmd.Execute()
assert.NoError(err)
assert.Equal(10, restGatewayConf.MaxTXWaitTime)
assert.Equal(1, restGatewayConf.Events.PollingIntervalSec)

// test that the environment variable FC_HTTP_PORT overrides the port setting in the config file
assert.Equal(8002, restGatewayConf.HTTP.Port)
Expand All @@ -117,20 +118,23 @@ func TestEnvVarOverride(t *testing.T) {
rootCmd.RunE = runNothing
_ = rootCmd.Execute()
assert.Equal(8002, restGatewayConf.HTTP.Port)
assert.Equal(uint64(60), restGatewayConf.Events.PollingIntervalSec)
assert.Equal(60, restGatewayConf.MaxInFlight)
}

func TestCmdArgsOverride(t *testing.T) {
assert := assert.New(t)

restGateway = nil
restGatewayConf.Events.PollingIntervalSec = 0
rootCmd.RunE = runNothing
args := []string{
"-P", "8001",
"--events-polling-int", "10",
}
rootCmd.SetArgs(args)
_ = rootCmd.Execute()
assert.Equal(8001, restGatewayConf.HTTP.Port)
assert.Equal(10, restGatewayConf.Events.PollingIntervalSec)
}

func TestDefaultsInConfigFile(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type LevelDBReceiptsConf struct {
}

type EventstreamConf struct {
PollingIntervalSec uint64 `mapstructure:"pollingInterval"`
PollingIntervalSec int `mapstructure:"pollingInterval"`
WebhooksAllowPrivateIPs bool `json:"webhooksAllowPrivateIPs,omitempty"`
LevelDB LevelDBReceiptsConf `mapstructure:"leveldb"`
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func CobraInit(cmd *cobra.Command, conf *RESTGatewayConf) {

cmd.Flags().StringVarP(&conf.Events.LevelDB.Path, "events-db", "E", "", "Level DB location for subscription management")
_ = viper.BindPFlag("events.leveldb.path", cmd.Flags().Lookup("events-db"))
cmd.Flags().Uint64VarP(&conf.Events.PollingIntervalSec, "events-polling-int", "", 10, "Event polling interval (ms)")
cmd.Flags().IntVarP(&conf.Events.PollingIntervalSec, "events-polling-int", "", 1, "Event polling interval (seconds)")
_ = viper.BindPFlag("events.pollingInterval", cmd.Flags().Lookup("events-polling-int"))
cmd.Flags().BoolVarP(&conf.Events.WebhooksAllowPrivateIPs, "events-priv-ips", "", false, "Allow private IPs in Webhooks")
_ = viper.BindPFlag("events.webhooksAllowPrivateIPs", cmd.Flags().Lookup("events-priv-ips"))
Expand Down

0 comments on commit 166f927

Please sign in to comment.