Skip to content

Commit

Permalink
add test for concurrent map write, must use -race flag
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jan 5, 2024
1 parent 599eed7 commit 56caa15
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 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,32 @@ func TestInvalidUnixTimes(t *testing.T) {
_, err = unixToTime("464")
require.Error(t, err)
}

func TestMapPool(t *testing.T) {
//for _, tt := range tests {
// t.Run(tt.fmt, func(t *testing.T) {
ls := labels.FromStrings("cluster", "us-central-0")
builder := NewBaseLabelsBuilder().ForLabels(ls, ls.Hash())
wg := sync.WaitGroup{}
wg.Add(1)
for i := 0; i < 100; i++ {
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}}`)
for j := 0; j < 100; j++ {
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,
)
}

}()

}
wg.Done()
time.Sleep(2 * time.Second)

//require.Equal(t, tt.want, newMustLineFormatter(tt.fmt).RequiredLabelNames())
//})
//}
}

0 comments on commit 56caa15

Please sign in to comment.