pkg/log: fix data race on d (#2698)
* pkg/log: fix data race on d Wrap d in a mutex to prevent data race. This makes is slower, but this is a debugging aid anyway. It's not used normally. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests compilation Signed-off-by: Miek Gieben <miek@miek.nl> * Fix test compile Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
118b0c9408
commit
a84413bd07
6 changed files with 47 additions and 26 deletions
|
@ -17,10 +17,21 @@ func msg() *dns.Msg {
|
|||
m.SetQuestion("example.local.", dns.TypeA)
|
||||
m.SetEdns0(4096, true)
|
||||
m.Id = 10
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func TestNoDebug(t *testing.T) {
|
||||
// Must come first, because set log.D.Set() which is impossible to undo.
|
||||
var f bytes.Buffer
|
||||
golog.SetOutput(&f)
|
||||
|
||||
str := "Hi There!"
|
||||
Hexdumpf(msg(), "%s %d", str, 10)
|
||||
if len(f.Bytes()) != 0 {
|
||||
t.Errorf("Expected no output, got %d bytes", len(f.Bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleLogHexdump() {
|
||||
buf, _ := msg().Pack()
|
||||
h := hexdump(buf)
|
||||
|
@ -36,7 +47,7 @@ func ExampleLogHexdump() {
|
|||
func TestHexdump(t *testing.T) {
|
||||
var f bytes.Buffer
|
||||
golog.SetOutput(&f)
|
||||
log.D = true
|
||||
log.D.Set()
|
||||
|
||||
str := "Hi There!"
|
||||
Hexdump(msg(), str)
|
||||
|
@ -50,7 +61,7 @@ func TestHexdump(t *testing.T) {
|
|||
func TestHexdumpf(t *testing.T) {
|
||||
var f bytes.Buffer
|
||||
golog.SetOutput(&f)
|
||||
log.D = true
|
||||
log.D.Set()
|
||||
|
||||
str := "Hi There!"
|
||||
Hexdumpf(msg(), "%s %d", str, 10)
|
||||
|
@ -60,15 +71,3 @@ func TestHexdumpf(t *testing.T) {
|
|||
t.Errorf("The string %s %d, is not contained in the logged output: %s", str, 10, logged)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoDebug(t *testing.T) {
|
||||
var f bytes.Buffer
|
||||
golog.SetOutput(&f)
|
||||
log.D = false
|
||||
|
||||
str := "Hi There!"
|
||||
Hexdumpf(msg(), "%s %d", str, 10)
|
||||
if len(f.Bytes()) != 0 {
|
||||
t.Errorf("Expected no output, got %d bytes", len(f.Bytes()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue