Skip to content

Commit

Permalink
increase test coverage, bump nats ver, failfast (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenye authored Jan 14, 2024
1 parent c5d055d commit 4877dab
Show file tree
Hide file tree
Showing 20 changed files with 941 additions and 200 deletions.
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 @@ import (
"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 @@ var (
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)
}

// When app was started. To calculate uptime.
startTime time.Time
)
Expand All @@ -215,17 +229,16 @@ func main() {
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)
} else {
log.Info().Msg("finished without error")
os.Exit(0)
Finish(0)
}
}

Expand Down Expand Up @@ -307,7 +320,11 @@ func runServer(cliContext *cli.Context) error {
defer cleanExit()

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

// initial logging
log.Info().Msg(banner) // show awesome banner
Expand Down Expand Up @@ -386,7 +403,7 @@ func runServer(cliContext *cli.Context) error {
}

// 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 @@ func runServer(cliContext *cli.Context) error {
// 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")
}

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

0 comments on commit 4877dab

Please sign in to comment.