diff options
author | 2019-05-23 21:02:30 +0100 | |
---|---|---|
committer | 2019-05-23 21:02:30 +0100 | |
commit | a84413bd07fddefdf967d244aa4fafad24923737 (patch) | |
tree | 0686abdf979c0507173e933a6b03b35bf68a7ee6 /plugin/debug/pcap_test.go | |
parent | 118b0c940890161d185b64497605a7ef84c38a0a (diff) | |
download | coredns-a84413bd07fddefdf967d244aa4fafad24923737.tar.gz coredns-a84413bd07fddefdf967d244aa4fafad24923737.tar.zst coredns-a84413bd07fddefdf967d244aa4fafad24923737.zip |
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>
Diffstat (limited to 'plugin/debug/pcap_test.go')
-rw-r--r-- | plugin/debug/pcap_test.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/plugin/debug/pcap_test.go b/plugin/debug/pcap_test.go index 724189db7..b2796e399 100644 --- a/plugin/debug/pcap_test.go +++ b/plugin/debug/pcap_test.go @@ -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())) - } -} |