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

increase test coverage, bump nats ver, failfast #57

Merged
merged 2 commits into from
Jan 14, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
name: go test
run: |
pushd bordercontrol
sudo go test -v -timeout 8m --race -count=2 -coverprofile=../coverage.out -covermode=atomic ./...
sudo go test -v -timeout 15m -failfast -race -count=2 -coverprofile=../coverage.out -covermode=atomic ./...
-
name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
37 changes: 30 additions & 7 deletions bordercontrol/cmd/bordercontrol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"pw_bordercontrol/lib/feedprotocol"
"pw_bordercontrol/lib/feedproxy"
"pw_bordercontrol/lib/listener"
"pw_bordercontrol/lib/logging"
"pw_bordercontrol/lib/nats_io"
"pw_bordercontrol/lib/stats"
"pw_bordercontrol/lib/stunnel"
Expand Down Expand Up @@ -194,9 +193,24 @@
Value: "",
EnvVars: []string{"NATS_INSTANCE"},
},
&cli.BoolFlag{
Category: "Logging",
Name: "verbose",
Usage: "Change default log level from Info to Debug",
Value: false,
EnvVars: []string{"BC_VERBOSE"},
},
},
}

// channel for SIGTERM
sigTermChan = make(chan os.Signal)

// finish is a wrapper for os.Exit that can be overridden for testing
Finish = func(code int) {
os.Exit(code)
}

Check warning on line 212 in bordercontrol/cmd/bordercontrol/main.go

View check run for this annotation

Codecov / codecov/patch

bordercontrol/cmd/bordercontrol/main.go#L210-L212

Added lines #L210 - L212 were not covered by tests

// When app was started. To calculate uptime.
startTime time.Time
)
Expand All @@ -215,17 +229,16 @@
app.Action = runServer

// set up logging
logging.IncludeVerbosityFlags(&app)
logging.ConfigureForCli()
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.UnixDate})

// run & final exit
err := app.Run(os.Args)
if err != nil {
log.Err(err).Msg("finished with error")
os.Exit(1)
Finish(1)

Check warning on line 238 in bordercontrol/cmd/bordercontrol/main.go

View check run for this annotation

Codecov / codecov/patch

bordercontrol/cmd/bordercontrol/main.go#L238

Added line #L238 was not covered by tests
} else {
log.Info().Msg("finished without error")
os.Exit(0)
Finish(0)
}
}

Expand Down Expand Up @@ -307,7 +320,11 @@
defer cleanExit()

// Set logging level
logging.SetLoggingLevel(cliContext)
if cliContext.Bool("verbose") {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}

Check warning on line 327 in bordercontrol/cmd/bordercontrol/main.go

View check run for this annotation

Codecov / codecov/patch

bordercontrol/cmd/bordercontrol/main.go#L326-L327

Added lines #L326 - L327 were not covered by tests

// initial logging
log.Info().Msg(banner) // show awesome banner
Expand Down Expand Up @@ -386,7 +403,7 @@
}

// set up channel to catch SIGTERM
sigTermChan := make(chan os.Signal)
// sigTermChan =
signal.Notify(sigTermChan, syscall.SIGTERM)

// handle SIGTERM
Expand Down Expand Up @@ -419,6 +436,12 @@
// wait for listeners to finish (until context closure)
wg.Wait()

// stop container manager
err = feedproxy.Close(&feedProxyConf)
if err != nil {
log.Err(err).Msg("error closing proxy subsystem")
}

Check warning on line 443 in bordercontrol/cmd/bordercontrol/main.go

View check run for this annotation

Codecov / codecov/patch

bordercontrol/cmd/bordercontrol/main.go#L442-L443

Added lines #L442 - L443 were not covered by tests

// stop container manager
err = ContainerManager.Stop()
if err != nil {
Expand Down
Loading