MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestCollectStackTraceFile

Function TestCollectStackTraceFile

rest/server_context_test.go:1065–1094  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1063}
1064
1065func TestCollectStackTraceFile(t *testing.T) {
1066 base.SetUpTestLogging(t, base.LevelInfo, base.KeyAll)
1067
1068 tempPath := t.TempDir()
1069 serverConfig := DefaultStartupConfig(tempPath)
1070 serverConfig.Logging.LogFilePath = tempPath
1071 ctx := t.Context()
1072 serverContext := NewServerContext(ctx, &serverConfig, false)
1073 defer serverContext.Close(ctx)
1074
1075 timeStamp := "01"
1076 stackTrace, err := base.GetStackTrace()
1077 require.NoError(t, err)
1078 base.LogStackTraces(ctx, serverConfig.Logging.LogFilePath, stackTrace, timeStamp)
1079 require.Len(t, getFilenames(t, tempPath), 1)
1080 assert.True(t, slices.Contains(getFilenames(t, tempPath), base.StackFilePrefix+timeStamp+".log"))
1081
1082 // trigger rotation and assert we don't go above 10 files
1083 expectedFiles := make([]string, 0, 10)
1084 for i := 2; i < 12; i++ {
1085 timeStamp = fmt.Sprintf("%d", i+2)
1086 trace, err := base.GetStackTrace()
1087 require.NoError(t, err)
1088 base.LogStackTraces(ctx, serverConfig.Logging.LogFilePath, trace, timeStamp)
1089 expectedFiles = append(expectedFiles, base.StackFilePrefix+timeStamp+".log")
1090 }
1091 files := getFilenames(t, tempPath)
1092 require.Len(t, files, 10)
1093 require.ElementsMatch(t, files, expectedFiles)
1094}

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
SetUpTestLoggingFunction · 0.92
GetStackTraceFunction · 0.92
LogStackTracesFunction · 0.92
DefaultStartupConfigFunction · 0.85
NewServerContextFunction · 0.85
getFilenamesFunction · 0.85
ContextMethod · 0.65
LenMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected