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

Tested debug sync #2

Merged
merged 7 commits into from
Sep 20, 2022
Merged

Tested debug sync #2

merged 7 commits into from
Sep 20, 2022

Conversation

jbsv
Copy link
Contributor

@jbsv jbsv commented Sep 14, 2022

  • Added unit tests on mutex, rwmutex and waitgroup
  • Uses the native functionality by default. Debug version enabled by env. variable DBGSYNCON=true
  • Allow different level of traces with env. variable setting, e.g. DBGSYNCLOG=info

.golangci.yaml Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
2nd attempt to remove useless lint warnings

fix make check
Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the tests refactoring, to ensure we have full coverage 👍
There are still a few (minor) issues though before I'd be comfortable merging.

mod.go Outdated
// LLVL=trace go test ./...
// LLVL=info go test ./...
// DBGSYNCLOG=trace go test ./...
// DBGSYNCLOG=info go test ./...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mention the DebugFlag here as well ?

mod.go Outdated

const defaultLevel = zerolog.NoLevel

func init() {
dbg := os.Getenv(DebugFlag)
DebugIsOn = dbg == "true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about a case insensitive comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really just a matter of taste, no ? Maybe we should pick "1" or "0" as possibilities ;-)

mod.go Outdated
@@ -16,11 +17,15 @@ import (

// EnvLogLevel is the name of the environment variable to change the logging
// level.
const EnvLogLevel = "LLVL"
const EnvLogLevel = "DBGSYNCLOG"
const DebugFlag = "DBGSYNCON"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this constant is missing documentation

rwmutex.go Outdated
Comment on lines 134 to 136
// when m.wg goes bellow zero,
// we need to recover from panic for the unit tests,
// re-init the wg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// when m.wg goes bellow zero,
// we need to recover from panic for the unit tests,
// re-init the wg
// when the WaitGroup goes below zero,
// we need to recover from panic,
// and re-initialize it

suggestion for a tiny phrasing fix, not sure where the 80 characters limit is 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for my French

m.wg.Done()
defer func() {
err := recover()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use errors.Is to verify that the err is indeed because we went below 0, or match a string ?
( I don't remember if recover provides an error or a string, and if it's a string if we have a type to compare it to )

I'm just thinking it would be a pity to "hide" an unrelated panic, somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The return value of recover is the error raised in the call to panic." Hard to use a Is(...) in this case. But maybe I could check if the wg goes bellow zero ?

rwmutex_test.go Outdated
Comment on lines 16 to 17
// There is a modified copy of this file in runtime/rwmutex_test.go.
// If you make any changes here, see if you should make them there.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? I assume this is left over from something older, right?
I don't think anybody maintaining this code is going to make changes to the Go runtime standard library 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove that 😄

Comment on lines +1 to +3
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd 😁

Shouldn't we add a header mentioning that this is based off the sync standard library tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very uncomfortable with this licensing stuff and yes, I like your proposition.

Comment on lines +1 to +4
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd 😁

Shouldn't we add a header mentioning that this is based off the sync standard library tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Comment on lines +1 to +3
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd 😁

Shouldn't we add a header mentioning that this is based off the sync standard library tests ?

@sonarcloud
Copy link

sonarcloud bot commented Sep 20, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

87.1% 87.1% Coverage
0.0% 0.0% Duplication

@jbsv jbsv merged commit 13287a3 into main Sep 20, 2022
@jbsv jbsv deleted the tested_debug_sync branch September 20, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants