Skip to content

Commit

Permalink
add a test that will panic on the pool Get calls
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jan 8, 2024
1 parent 2037966 commit d44061a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/logql/log/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -923,3 +924,46 @@ func TestInvalidUnixTimes(t *testing.T) {
_, err = unixToTime("464")
require.Error(t, err)
}

func TestMapPool(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
wgFinished := sync.WaitGroup{}

ls := labels.FromStrings("cluster", "us-central-0")
builder := NewBaseLabelsBuilder().ForLabels(ls, ls.Hash())
a := newMustLineFormatter(`[1m{{if .level }}{{alignRight 5 .level}}{{else if .severity}}{{alignRight 5 .severity}}{{end}}[0m [90m[{{alignRight 10 .resources_service_instance_id}}{{if .attributes_thread_name}}/{{alignRight 20 .attributes_thread_name}}{{else if eq "java" .resources_telemetry_sdk_language }} {{end}}][0m [36m{{if .instrumentation_scope_name }}{{alignRight 40 .instrumentation_scope_name}}{{end}}[0m {{.body}} {{if .traceid}} [37m[3m[traceid={{.traceid}}]{{end}}`)
a.Process(0,
[]byte("logger=sqlstore.metrics traceID=XXXXXXXXXXXXXXXXXXXXXXXXXXXX t=2024-01-04T23:58:47.696779826Z level=debug msg=\"query finished\" status=success elapsedtime=1.523571ms sql=\"some SQL query\" error=null"),
builder,
)

for i := 0; i < 100; i++ {
wgFinished.Add(1)
go func() {
wg.Wait()
a := newMustLineFormatter(`[1m{{if .level }}{{alignRight 5 .level}}{{else if .severity}}{{alignRight 5 .severity}}{{end}}[0m [90m[{{alignRight 10 .resources_service_instance_id}}{{if .attributes_thread_name}}/{{alignRight 20 .attributes_thread_name}}{{else if eq "java" .resources_telemetry_sdk_language }} {{end}}][0m [36m{{if .instrumentation_scope_name }}{{alignRight 40 .instrumentation_scope_name}}{{end}}[0m {{.body}} {{if .traceid}} [37m[3m[traceid={{.traceid}}]{{end}}`)
a.Process(0,
[]byte("logger=sqlstore.metrics traceID=XXXXXXXXXXXXXXXXXXXXXXXXXXXX t=2024-01-04T23:58:47.696779826Z level=debug msg=\"query finished\" status=success elapsedtime=1.523571ms sql=\"some SQL query\" error=null"),
builder,
)
wgFinished.Done()
}()
}
for i := 0; i < 100; i++ {
wgFinished.Add(1)
j := i
go func() {
wg.Wait()
m := smp.Get()
for k, v := range m {
m[k] = fmt.Sprintf("%s%d", v, j)
}
smp.Put(m)
wgFinished.Done()

}()
}
wg.Done()
wgFinished.Wait()
}

0 comments on commit d44061a

Please sign in to comment.