Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlv committed Nov 22, 2024
1 parent 1ecdcd4 commit 9dc1b79
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ unittest:
#/opt/hostedtoolcache/go/1.21.13/x64/bin/go test -v ./pkg/trs_http_api/... -cover -logLevel=2
#/opt/hostedtoolcache/go/1.22.9/x64/bin/go test -v ./pkg/trs_http_api/... -cover -logLevel=2
#/opt/hostedtoolcache/go/1.23.3/x64/bin/go test -v ./pkg/trs_http_api/... -cover -logLevel=2
#
#
# -logLevel values: 0=Panic, 1=Fatal, 2=Error 3=Warn, 4=Info, 5=Debug, 6=Trace"
#

go test -v ./pkg/trs_http_api/... -cover -logLevel=2

# no -v -tags musl

integration:
Expand Down
2 changes: 1 addition & 1 deletion pkg/trs_http_api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type RetryPolicy struct {
}

type HttpTxPolicy struct {
Enabled bool // Enable or disable the policy
Enabled bool // Enable or disable the policy
MaxIdleConns int
MaxIdleConnsPerHost int
IdleConnTimeout time.Duration
Expand Down
7 changes: 3 additions & 4 deletions pkg/trs_http_api/trshttp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (c *trsRoundTripper) trsCheckRetry(ctx context.Context, resp *http.Response
c.skipCloseMutex.Unlock()

//wrapperLogger.Errorf("trsCheckRetry: skipCloseCount now %v and err is %v", c.skipCloseCount, err)

return false, err
}
}
Expand Down Expand Up @@ -745,8 +745,8 @@ func (tloc *TRSHTTPLocal) Close(taskList *[]HttpTask) {
v.contextCancel()

// The caller should have closed the response body, but we'll also
// do it here to both prevent resource leaks. Note that if that
// was the case, that connection was closed by the above cancel.
// do it here to prevent resource leaks. Note that if that was
// the case, that connection was closed by the above cancel.

if v.Request.Response != nil && v.Request.Response.Body != nil {
_, _ = io.Copy(io.Discard, v.Request.Response.Body)
Expand Down Expand Up @@ -796,5 +796,4 @@ func (tloc *TRSHTTPLocal) Cleanup() {
}
tloc.Logger.Tracef("Cleanup() completed")
// this really just a big red button to STOP ALL? b/c im not clearing any memory
// TEST
}
32 changes: 19 additions & 13 deletions pkg/trs_http_api/trshttp_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ import (
var svcName = "TestMe"

// Note for unit test and TRS loggers: Log level can be controlled by
// by modifying the
// by modifying the -logLevel command line option in the Makefile

var logLevel logrus.Level // use this for more than logrus

// TestMain is not a test. It runs before all other tests so that it can
// do any necessary initialization. Here we pars the command line arges
// so we can apply any log level override for the unit test loggers
func TestMain(m *testing.M) {
var logLevelInt int

Expand All @@ -70,7 +74,7 @@ func TestMain(m *testing.M) {
}

// Create a logger for trs_http_api (not unit tests) so we can see what's
// going on in TRS when we hit errors
// going on in TRS when we hit issues.
func createLogger() *logrus.Logger {
trsLogger := logrus.New()

Expand Down Expand Up @@ -138,7 +142,8 @@ func hasUserAgentHeader(r *http.Request) bool {
}

_,ok := r.Header["User-Agent"]
return ok

return ok
}

// Check header for "Trs-Fail-All-Retries"
Expand Down Expand Up @@ -462,12 +467,12 @@ func TestLaunchTimeout(t *testing.T) {
// * Marked "dirty" and could get cleaned up any time since the
// body was drained
//
// * If/wen IdleConnTimeout is exceeded (by default is 0 which means
// * If/when IdleConnTimeout is exceeded (by default is 0 which means
// no timeout in place), it will be closed and:
//
// * I couldn't find a definitive answer if a minimal
// resource leak (which would NOT include body data) would
// be permanent or not in the Go client
// be permanent or not in the Go client
// * Prior OS resource leak should now be freed (not sure I believe)
// * Prior Istio resource leak should now be freed (not sure I believe)
//
Expand All @@ -477,8 +482,9 @@ func TestLaunchTimeout(t *testing.T) {
// * OS connection state: open, unusable (resource leak)
// * Istio connection state: open, unusable (resource leak)
//
// * If/wen IdleConnTimeout is exceeded (by default is 0 which means
// no timeout in place), it will be closed and:
// * If/when IdleConnTimeout is exceeded (by default is 0 which means
// no timeout in place), OR if/when a context times out or is cancelled,
// it will be closed and:
//
// * Go client resource leak (including body data) will remain
// * Prior OS resource leak should now be freed (not sure I believe)
Expand Down Expand Up @@ -761,7 +767,7 @@ func logConnTestHeader(t *testing.T, a testConnsArg) {
t.Logf("")

if logLevel < logrus.ErrorLevel {
return
return
}

t.Logf(" nTasks: %v", a.nTasks)
Expand Down Expand Up @@ -958,7 +964,7 @@ func TestConnsWithHttpTxPolicy_PcsLargeBusy(t *testing.T) {
nIssues := 1000
maxIdleConnsPerHost := 8000 // We're only using one Host server so pretend
maxIdleConns := 8000 // 8000 requests / 4 per host = 2000 BMCs
pcsStatusTimeout := 60 // Increase for pitiful unit test vm
pcsStatusTimeout := 60 // Increase for pitiful unit test vm

testConnsWithHttpTxPolicy(t, nTasks, nIssues, maxIdleConnsPerHost, maxIdleConns, pcsStatusTimeout)
}
Expand Down Expand Up @@ -1210,7 +1216,7 @@ func testConnsPrep(t *testing.T, a testConnsArg, nTasks int, nIssues int) {
// Connection stays open if the body is never closed and is not reusable
// for any other requests (unless body is later drained/closed)
//
// However, because it was marked "dirty" it can get cleaned up by
// However, because it was marked "dirty" it can get cleaned up by
// the system at any time. I've seen that using 'ss' in the tests
// can force this to happen immediately after tasks complete if the
// number of open connections is greater than maxIdleConnsPerHost
Expand Down Expand Up @@ -1411,8 +1417,8 @@ func runTaskList(t *testing.T, tloc *TRSHTTPLocal, a testConnsArg, srv *httptest

req, err := http.NewRequest(http.MethodGet, srv.URL, nil)
if err != nil {
t.Fatalf("=====> ERROR: Failed to create request: %v <=====", err)
}
t.Fatalf("=====> ERROR: Failed to create request: %v <=====", err)
}

// Set any necessary headers

Expand Down Expand Up @@ -1753,4 +1759,4 @@ func runTaskList(t *testing.T, tloc *TRSHTTPLocal, a testConnsArg, srv *httptest

testOpenConnections(t, 0)
}
}
}

0 comments on commit 9dc1b79

Please sign in to comment.