mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
tests: Do not allow forced type asserts (#20905)
This commit is contained in:
@@ -1748,20 +1748,20 @@ func (c *Connection) debugMsg(d debugMsg, args ...any) {
|
||||
case debugSetConnPingDuration:
|
||||
c.connMu.Lock()
|
||||
defer c.connMu.Unlock()
|
||||
c.connPingInterval = args[0].(time.Duration)
|
||||
c.connPingInterval, _ = args[0].(time.Duration)
|
||||
if c.connPingInterval < time.Second {
|
||||
panic("CONN ping interval too low")
|
||||
}
|
||||
case debugSetClientPingDuration:
|
||||
c.connMu.Lock()
|
||||
defer c.connMu.Unlock()
|
||||
c.clientPingInterval = args[0].(time.Duration)
|
||||
c.clientPingInterval, _ = args[0].(time.Duration)
|
||||
case debugAddToDeadline:
|
||||
c.addDeadline = args[0].(time.Duration)
|
||||
c.addDeadline, _ = args[0].(time.Duration)
|
||||
case debugIsOutgoingClosed:
|
||||
// params: muxID uint64, isClosed func(bool)
|
||||
muxID := args[0].(uint64)
|
||||
resp := args[1].(func(b bool))
|
||||
muxID, _ := args[0].(uint64)
|
||||
resp, _ := args[1].(func(b bool))
|
||||
mid, ok := c.outgoing.Load(muxID)
|
||||
if !ok || mid == nil {
|
||||
resp(true)
|
||||
@@ -1772,7 +1772,8 @@ func (c *Connection) debugMsg(d debugMsg, args ...any) {
|
||||
mid.respMu.Unlock()
|
||||
case debugBlockInboundMessages:
|
||||
c.connMu.Lock()
|
||||
block := (<-chan struct{})(args[0].(chan struct{}))
|
||||
a, _ := args[0].(chan struct{})
|
||||
block := (<-chan struct{})(a)
|
||||
c.blockMessages.Store(&block)
|
||||
c.connMu.Unlock()
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gobwas/ws"
|
||||
"github.com/gobwas/ws/wsutil"
|
||||
"github.com/minio/minio/internal/bpool"
|
||||
)
|
||||
|
||||
// ErrDisconnected is returned when the connection to the remote has been lost during the call.
|
||||
@@ -68,15 +68,15 @@ const (
|
||||
defaultSingleRequestTimeout = time.Minute
|
||||
)
|
||||
|
||||
var internalByteBuffer = sync.Pool{
|
||||
New: func() any {
|
||||
var internalByteBuffer = bpool.Pool[*[]byte]{
|
||||
New: func() *[]byte {
|
||||
m := make([]byte, 0, defaultBufferSize)
|
||||
return &m
|
||||
},
|
||||
}
|
||||
|
||||
var internal32KByteBuffer = sync.Pool{
|
||||
New: func() any {
|
||||
var internal32KByteBuffer = bpool.Pool[*[]byte]{
|
||||
New: func() *[]byte {
|
||||
m := make([]byte, 0, biggerBufMin)
|
||||
return &m
|
||||
},
|
||||
@@ -87,7 +87,7 @@ var internal32KByteBuffer = sync.Pool{
|
||||
// When replacing PutByteBuffer should also be replaced
|
||||
// There is no minimum size.
|
||||
var GetByteBuffer = func() []byte {
|
||||
b := *internalByteBuffer.Get().(*[]byte)
|
||||
b := *internalByteBuffer.Get()
|
||||
return b[:0]
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func GetByteBufferCap(wantSz int) []byte {
|
||||
PutByteBuffer(b)
|
||||
}
|
||||
if wantSz <= maxBufferSize {
|
||||
b := *internal32KByteBuffer.Get().(*[]byte)
|
||||
b := *internal32KByteBuffer.Get()
|
||||
if cap(b) >= wantSz {
|
||||
return b[:0]
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/minio/minio/internal/bpool"
|
||||
"github.com/minio/minio/internal/hash/sha256"
|
||||
xioutil "github.com/minio/minio/internal/ioutil"
|
||||
"github.com/tinylib/msgp/msgp"
|
||||
@@ -431,12 +431,12 @@ func recycleFunc[RT RoundTripper](newRT func() RT) (newFn func() RT, recycle fun
|
||||
}
|
||||
}
|
||||
}
|
||||
pool := sync.Pool{
|
||||
New: func() interface{} {
|
||||
pool := bpool.Pool[RT]{
|
||||
New: func() RT {
|
||||
return newRT()
|
||||
},
|
||||
}
|
||||
return func() RT { return pool.Get().(RT) },
|
||||
return pool.Get,
|
||||
func(r RT) {
|
||||
if r != rZero {
|
||||
//nolint:staticcheck // SA6002 IT IS A GENERIC VALUE!
|
||||
@@ -632,8 +632,8 @@ type StreamTypeHandler[Payload, Req, Resp RoundTripper] struct {
|
||||
// Will be 0 if newReq is nil.
|
||||
InCapacity int
|
||||
|
||||
reqPool sync.Pool
|
||||
respPool sync.Pool
|
||||
reqPool bpool.Pool[Req]
|
||||
respPool bpool.Pool[Resp]
|
||||
id HandlerID
|
||||
newPayload func() Payload
|
||||
nilReq Req
|
||||
@@ -653,13 +653,13 @@ func NewStream[Payload, Req, Resp RoundTripper](h HandlerID, newPayload func() P
|
||||
|
||||
s := newStreamHandler[Payload, Req, Resp](h)
|
||||
if newReq != nil {
|
||||
s.reqPool.New = func() interface{} {
|
||||
s.reqPool.New = func() Req {
|
||||
return newReq()
|
||||
}
|
||||
} else {
|
||||
s.InCapacity = 0
|
||||
}
|
||||
s.respPool.New = func() interface{} {
|
||||
s.respPool.New = func() Resp {
|
||||
return newResp()
|
||||
}
|
||||
s.newPayload = newPayload
|
||||
@@ -682,7 +682,7 @@ func (h *StreamTypeHandler[Payload, Req, Resp]) NewPayload() Payload {
|
||||
// NewRequest creates a new request.
|
||||
// The struct may be reused, so caller should clear any fields.
|
||||
func (h *StreamTypeHandler[Payload, Req, Resp]) NewRequest() Req {
|
||||
return h.reqPool.Get().(Req)
|
||||
return h.reqPool.Get()
|
||||
}
|
||||
|
||||
// PutRequest will accept a request for reuse.
|
||||
@@ -706,7 +706,7 @@ func (h *StreamTypeHandler[Payload, Req, Resp]) PutResponse(r Resp) {
|
||||
// NewResponse creates a new response.
|
||||
// Handlers can use this to create a reusable response.
|
||||
func (h *StreamTypeHandler[Payload, Req, Resp]) NewResponse() Resp {
|
||||
return h.respPool.Get().(Resp)
|
||||
return h.respPool.Get()
|
||||
}
|
||||
|
||||
func newStreamHandler[Payload, Req, Resp RoundTripper](h HandlerID) *StreamTypeHandler[Payload, Req, Resp] {
|
||||
|
||||
@@ -388,6 +388,5 @@ func (m *muxServer) close() {
|
||||
if m.outBlock != nil {
|
||||
xioutil.SafeClose(m.outBlock)
|
||||
m.outBlock = nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/minio/minio/internal/bpool"
|
||||
"github.com/tinylib/msgp/msgp"
|
||||
)
|
||||
|
||||
@@ -53,7 +54,7 @@ func (m *MSS) Get(key string) string {
|
||||
// Set a key, value pair.
|
||||
func (m *MSS) Set(key, value string) {
|
||||
if m == nil {
|
||||
*m = mssPool.Get().(map[string]string)
|
||||
*m = mssPool.Get()
|
||||
}
|
||||
(*m)[key] = value
|
||||
}
|
||||
@@ -130,7 +131,7 @@ func (m *MSS) Msgsize() int {
|
||||
|
||||
// NewMSS returns a new MSS.
|
||||
func NewMSS() *MSS {
|
||||
m := MSS(mssPool.Get().(map[string]string))
|
||||
m := MSS(mssPool.Get())
|
||||
for k := range m {
|
||||
delete(m, k)
|
||||
}
|
||||
@@ -143,8 +144,8 @@ func NewMSSWith(m map[string]string) *MSS {
|
||||
return &m2
|
||||
}
|
||||
|
||||
var mssPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
var mssPool = bpool.Pool[map[string]string]{
|
||||
New: func() map[string]string {
|
||||
return make(map[string]string, 5)
|
||||
},
|
||||
}
|
||||
@@ -152,7 +153,7 @@ var mssPool = sync.Pool{
|
||||
// Recycle the underlying map.
|
||||
func (m *MSS) Recycle() {
|
||||
if m != nil && *m != nil {
|
||||
mssPool.Put(map[string]string(*m))
|
||||
mssPool.Put(*m)
|
||||
*m = nil
|
||||
}
|
||||
}
|
||||
@@ -279,15 +280,15 @@ func (b *Bytes) Recycle() {
|
||||
// URLValues can be used for url.Values.
|
||||
type URLValues map[string][]string
|
||||
|
||||
var urlValuesPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
var urlValuesPool = bpool.Pool[map[string][]string]{
|
||||
New: func() map[string][]string {
|
||||
return make(map[string][]string, 10)
|
||||
},
|
||||
}
|
||||
|
||||
// NewURLValues returns a new URLValues.
|
||||
func NewURLValues() *URLValues {
|
||||
u := URLValues(urlValuesPool.Get().(map[string][]string))
|
||||
u := URLValues(urlValuesPool.Get())
|
||||
return &u
|
||||
}
|
||||
|
||||
@@ -342,7 +343,7 @@ func (u *URLValues) UnmarshalMsg(bts []byte) (o []byte, err error) {
|
||||
return
|
||||
}
|
||||
if *u == nil {
|
||||
*u = urlValuesPool.Get().(map[string][]string)
|
||||
*u = urlValuesPool.Get()
|
||||
}
|
||||
if len(*u) > 0 {
|
||||
for key := range *u {
|
||||
@@ -424,9 +425,11 @@ func NewJSONPool[T any]() *JSONPool[T] {
|
||||
|
||||
func (p *JSONPool[T]) new() *T {
|
||||
var zero T
|
||||
t := p.pool.Get().(*T)
|
||||
*t = zero
|
||||
return t
|
||||
if t, ok := p.pool.Get().(*T); ok {
|
||||
*t = zero
|
||||
return t
|
||||
}
|
||||
return &zero
|
||||
}
|
||||
|
||||
// JSON is a wrapper around a T object that can be serialized.
|
||||
@@ -557,15 +560,15 @@ func (NoPayload) Recycle() {}
|
||||
|
||||
// ArrayOf wraps an array of Messagepack compatible objects.
|
||||
type ArrayOf[T RoundTripper] struct {
|
||||
aPool sync.Pool // Arrays
|
||||
ePool sync.Pool // Elements
|
||||
aPool sync.Pool // Arrays
|
||||
ePool bpool.Pool[T] // Elements
|
||||
}
|
||||
|
||||
// NewArrayOf returns a new ArrayOf.
|
||||
// You must provide a function that returns a new instance of T.
|
||||
func NewArrayOf[T RoundTripper](newFn func() T) *ArrayOf[T] {
|
||||
return &ArrayOf[T]{
|
||||
ePool: sync.Pool{New: func() any {
|
||||
ePool: bpool.Pool[T]{New: func() T {
|
||||
return newFn()
|
||||
}},
|
||||
}
|
||||
@@ -609,7 +612,7 @@ func (p *ArrayOf[T]) putA(v []T) {
|
||||
}
|
||||
|
||||
func (p *ArrayOf[T]) newE() T {
|
||||
return p.ePool.Get().(T)
|
||||
return p.ePool.Get()
|
||||
}
|
||||
|
||||
// Array provides a wrapper for an underlying array of serializable objects.
|
||||
|
||||
Reference in New Issue
Block a user