forked from quic-go/quic-go
remove the testlog package
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"net"
|
||||
|
||||
quic "github.com/lucas-clemente/quic-go"
|
||||
_ "github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
quic "github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -93,7 +92,7 @@ var _ = Describe("Multiplexing", func() {
|
||||
close(done2)
|
||||
}()
|
||||
timeout := 30 * time.Second
|
||||
if testlog.Debug() {
|
||||
if debugLog() {
|
||||
timeout = time.Minute
|
||||
}
|
||||
Eventually(done1, timeout).Should(BeClosed())
|
||||
@@ -127,7 +126,7 @@ var _ = Describe("Multiplexing", func() {
|
||||
close(done2)
|
||||
}()
|
||||
timeout := 30 * time.Second
|
||||
if testlog.Debug() {
|
||||
if debugLog() {
|
||||
timeout = time.Minute
|
||||
}
|
||||
Eventually(done1, timeout).Should(BeClosed())
|
||||
@@ -157,7 +156,7 @@ var _ = Describe("Multiplexing", func() {
|
||||
close(done)
|
||||
}()
|
||||
timeout := 30 * time.Second
|
||||
if testlog.Debug() {
|
||||
if debugLog() {
|
||||
timeout = time.Minute
|
||||
}
|
||||
Eventually(done, timeout).Should(BeClosed())
|
||||
@@ -210,7 +209,7 @@ var _ = Describe("Multiplexing", func() {
|
||||
close(done2)
|
||||
}()
|
||||
timeout := 30 * time.Second
|
||||
if testlog.Debug() {
|
||||
if debugLog() {
|
||||
timeout = time.Minute
|
||||
}
|
||||
Eventually(done1, timeout).Should(BeClosed())
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package self_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
_ "github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
)
|
||||
|
||||
const alpn = "quic-go integration tests"
|
||||
@@ -50,6 +55,73 @@ func GeneratePRData(l int) []byte {
|
||||
return res
|
||||
}
|
||||
|
||||
const logBufSize = 100 * 1 << 20 // initial size of the log buffer: 100 MB
|
||||
|
||||
type syncedBuffer struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
*bytes.Buffer
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Write(p []byte) (int, error) {
|
||||
b.mutex.Lock()
|
||||
n, err := b.Buffer.Write(p)
|
||||
b.mutex.Unlock()
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Bytes() []byte {
|
||||
b.mutex.Lock()
|
||||
p := b.Buffer.Bytes()
|
||||
b.mutex.Unlock()
|
||||
return p
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Reset() {
|
||||
b.mutex.Lock()
|
||||
b.Buffer.Reset()
|
||||
b.mutex.Unlock()
|
||||
}
|
||||
|
||||
var (
|
||||
logFileName string // the log file set in the ginkgo flags
|
||||
logBufOnce sync.Once
|
||||
logBuf *syncedBuffer
|
||||
)
|
||||
|
||||
// read the logfile command line flag
|
||||
// to set call ginkgo -- -logfile=log.txt
|
||||
func init() {
|
||||
flag.StringVar(&logFileName, "logfile", "", "log file")
|
||||
}
|
||||
|
||||
var _ = BeforeEach(func() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
|
||||
|
||||
if debugLog() {
|
||||
logBufOnce.Do(func() {
|
||||
logBuf = &syncedBuffer{Buffer: bytes.NewBuffer(make([]byte, 0, logBufSize))}
|
||||
})
|
||||
utils.DefaultLogger.SetLogLevel(utils.LogLevelDebug)
|
||||
log.SetOutput(logBuf)
|
||||
}
|
||||
})
|
||||
|
||||
var _ = AfterEach(func() {
|
||||
if debugLog() {
|
||||
logFile, err := os.Create(logFileName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
logFile.Write(logBuf.Bytes())
|
||||
logFile.Close()
|
||||
logBuf.Reset()
|
||||
}
|
||||
})
|
||||
|
||||
// Debug says if this test is being logged
|
||||
func debugLog() bool {
|
||||
return len(logFileName) > 0
|
||||
}
|
||||
|
||||
func TestSelf(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Self integration tests")
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
package testlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
|
||||
//nolint:stylecheck
|
||||
. "github.com/onsi/ginkgo"
|
||||
//nolint:stylecheck
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
const logBufSize = 100 * 1 << 20 // initial size of the log buffer: 100 MB
|
||||
|
||||
type syncedBuffer struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
*bytes.Buffer
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Write(p []byte) (int, error) {
|
||||
b.mutex.Lock()
|
||||
n, err := b.Buffer.Write(p)
|
||||
b.mutex.Unlock()
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Bytes() []byte {
|
||||
b.mutex.Lock()
|
||||
p := b.Buffer.Bytes()
|
||||
b.mutex.Unlock()
|
||||
return p
|
||||
}
|
||||
|
||||
func (b *syncedBuffer) Reset() {
|
||||
b.mutex.Lock()
|
||||
b.Buffer.Reset()
|
||||
b.mutex.Unlock()
|
||||
}
|
||||
|
||||
var (
|
||||
logFileName string // the log file set in the ginkgo flags
|
||||
logBufOnce sync.Once
|
||||
logBuf *syncedBuffer
|
||||
)
|
||||
|
||||
// read the logfile command line flag
|
||||
// to set call ginkgo -- -logfile=log.txt
|
||||
func init() {
|
||||
flag.StringVar(&logFileName, "logfile", "", "log file")
|
||||
}
|
||||
|
||||
var _ = BeforeEach(func() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
|
||||
|
||||
if Debug() {
|
||||
logBufOnce.Do(func() {
|
||||
logBuf = &syncedBuffer{Buffer: bytes.NewBuffer(make([]byte, 0, logBufSize))}
|
||||
})
|
||||
utils.DefaultLogger.SetLogLevel(utils.LogLevelDebug)
|
||||
log.SetOutput(logBuf)
|
||||
}
|
||||
})
|
||||
|
||||
var _ = AfterEach(func() {
|
||||
if Debug() {
|
||||
logFile, err := os.Create(logFileName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
logFile.Write(logBuf.Bytes())
|
||||
logFile.Close()
|
||||
logBuf.Reset()
|
||||
}
|
||||
})
|
||||
|
||||
// Debug says if this test is being logged
|
||||
func Debug() bool {
|
||||
return len(logFileName) > 0
|
||||
}
|
||||
Reference in New Issue
Block a user