forked from quic-go/quic-go
use atomic.Bool from the standard library
This commit is contained in:
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
"github.com/quic-go/quic-go/internal/utils"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -30,7 +30,7 @@ var _ = Describe("Connection ID lengths tests", func() {
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var drop utils.AtomicBool
|
||||
var drop atomic.Bool
|
||||
dropped := make(chan []byte, 100)
|
||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||
@@ -38,7 +38,7 @@ var _ = Describe("Connection ID lengths tests", func() {
|
||||
return 5 * time.Millisecond // 10ms RTT
|
||||
},
|
||||
DropPacket: func(dir quicproxy.Direction, b []byte) bool {
|
||||
if drop := drop.Get(); drop && dir == quicproxy.DirectionOutgoing {
|
||||
if drop := drop.Load(); drop && dir == quicproxy.DirectionOutgoing {
|
||||
dropped <- b
|
||||
return true
|
||||
}
|
||||
@@ -58,7 +58,7 @@ var _ = Describe("Connection ID lengths tests", func() {
|
||||
sconn, err := server.Accept(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
drop.Set(true)
|
||||
drop.Store(true)
|
||||
sconn.CloseWithError(1337, "closing")
|
||||
|
||||
// send 100 packets
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/quic-go/quic-go/internal/utils"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -45,12 +45,11 @@ var _ = Describe("Stateless Resets", func() {
|
||||
ln.Close()
|
||||
}()
|
||||
|
||||
drop := utils.AtomicBool{}
|
||||
|
||||
var drop atomic.Bool
|
||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||
RemoteAddr: fmt.Sprintf("localhost:%d", serverPort),
|
||||
DropPacket: func(quicproxy.Direction, []byte) bool {
|
||||
return drop.Get()
|
||||
return drop.Load()
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -73,7 +72,7 @@ var _ = Describe("Stateless Resets", func() {
|
||||
Expect(data).To(Equal([]byte("foobar")))
|
||||
|
||||
// make sure that the CONNECTION_CLOSE is dropped
|
||||
drop.Set(true)
|
||||
drop.Store(true)
|
||||
close(closeServer)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
@@ -83,7 +82,7 @@ var _ = Describe("Stateless Resets", func() {
|
||||
serverConfig,
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
drop.Set(false)
|
||||
drop.Store(false)
|
||||
|
||||
acceptStopped := make(chan struct{})
|
||||
go func() {
|
||||
|
||||
@@ -124,12 +124,11 @@ var _ = Describe("Timeout tests", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}()
|
||||
|
||||
drop := utils.AtomicBool{}
|
||||
|
||||
var drop atomic.Bool
|
||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||
DropPacket: func(quicproxy.Direction, []byte) bool {
|
||||
return drop.Get()
|
||||
return drop.Load()
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -148,7 +147,7 @@ var _ = Describe("Timeout tests", func() {
|
||||
_, err = strIn.Read(make([]byte, 6))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
drop.Set(true)
|
||||
drop.Store(true)
|
||||
time.Sleep(2 * idleTimeout)
|
||||
_, err = strIn.Write([]byte("test"))
|
||||
checkTimeoutError(err)
|
||||
@@ -251,12 +250,12 @@ var _ = Describe("Timeout tests", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer server.Close()
|
||||
|
||||
drop := utils.AtomicBool{}
|
||||
var drop atomic.Bool
|
||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||
DropPacket: func(dir quicproxy.Direction, _ []byte) bool {
|
||||
if dir == quicproxy.DirectionOutgoing {
|
||||
return drop.Get()
|
||||
return drop.Load()
|
||||
}
|
||||
return false
|
||||
},
|
||||
@@ -282,7 +281,7 @@ var _ = Describe("Timeout tests", func() {
|
||||
|
||||
// wait half the idle timeout, then send a packet
|
||||
time.Sleep(idleTimeout / 2)
|
||||
drop.Set(true)
|
||||
drop.Store(true)
|
||||
str, err := conn.OpenUniStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = str.Write([]byte("foobar"))
|
||||
@@ -331,11 +330,11 @@ var _ = Describe("Timeout tests", func() {
|
||||
close(serverConnClosed)
|
||||
}()
|
||||
|
||||
drop := utils.AtomicBool{}
|
||||
var drop atomic.Bool
|
||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||
DropPacket: func(quicproxy.Direction, []byte) bool {
|
||||
return drop.Get()
|
||||
return drop.Load()
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -361,7 +360,7 @@ var _ = Describe("Timeout tests", func() {
|
||||
Consistently(serverConnClosed).ShouldNot(BeClosed())
|
||||
|
||||
// idle timeout will still kick in if pings are dropped
|
||||
drop.Set(true)
|
||||
drop.Store(true)
|
||||
time.Sleep(2 * idleTimeout)
|
||||
_, err = str.Write([]byte("foobar"))
|
||||
checkTimeoutError(err)
|
||||
|
||||
Reference in New Issue
Block a user