mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Preallocate auth.NewAnonymousCredentials() in contexttest.TestContext.
Otherwise every call to, say, fs.ContextCanAccessFile() in a benchmark using contexttest allocates new auth.Credentials, a new auth.UserNamespace, ... PiperOrigin-RevId: 254261051
This commit is contained in:
@@ -59,6 +59,7 @@ func Context(tb testing.TB) context.Context {
|
||||
l: limits.NewLimitSet(),
|
||||
mf: mf,
|
||||
platform: p,
|
||||
creds: auth.NewAnonymousCredentials(),
|
||||
otherValues: make(map[interface{}]interface{}),
|
||||
}
|
||||
}
|
||||
@@ -70,6 +71,7 @@ type TestContext struct {
|
||||
l *limits.LimitSet
|
||||
mf *pgalloc.MemoryFile
|
||||
platform platform.Platform
|
||||
creds *auth.Credentials
|
||||
otherValues map[interface{}]interface{}
|
||||
}
|
||||
|
||||
@@ -108,6 +110,8 @@ func (t *TestContext) RegisterValue(key, value interface{}) {
|
||||
// Value implements context.Context.
|
||||
func (t *TestContext) Value(key interface{}) interface{} {
|
||||
switch key {
|
||||
case auth.CtxCredentials:
|
||||
return t.creds
|
||||
case limits.CtxLimits:
|
||||
return t.l
|
||||
case pgalloc.CtxMemoryFile:
|
||||
|
||||
Reference in New Issue
Block a user