Skip to content

Commit 30b2a2d

Browse files
xelavopelkKlepov Alex
andauthored
fix integration test (#1879)
Co-authored-by: Klepov Alex <aklepov@rutube.ru>
1 parent c56ab1f commit 30b2a2d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Fixed race in integration test `TestTopicWriterLogMessagesWithoutData`
2+
13
## v3.117.0
24
* Fixed `conn/pool.Get()` behaviour for YDB databases with public IPs. Bug was introduced in v3.116.2
35
* Added helper methods `log.WithFields` and `log.FieldsFromContext` for working with structured logging fields via context.

tests/integration/topic_read_writer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ydb-platform/ydb-go-sdk/v3/internal/version"
2828
"github.com/ydb-platform/ydb-go-sdk/v3/log"
2929
xtest "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xtest"
30+
tu "github.com/ydb-platform/ydb-go-sdk/v3/testutil"
3031
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
3132
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicsugar"
3233
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
@@ -44,7 +45,7 @@ func TestTopicWriterLogMessagesWithoutData(t *testing.T) {
4445
metaKey := "gyoeexiufo"
4546
metaValue := "fjedeikeosbv"
4647

47-
logs := &strings.Builder{}
48+
logs := &tu.ThreadSafeBuilder{}
4849
writer, err := scope.Driver().Topic().StartWriter(
4950
scope.TopicPath(),
5051
topicoptions.WithWriterProducerID(producerID),

testutil/thread_safe_builder.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package testutil
2+
3+
import (
4+
"strings"
5+
"sync"
6+
)
7+
8+
type ThreadSafeBuilder struct {
9+
mu sync.Mutex
10+
b strings.Builder
11+
}
12+
13+
func (tsb *ThreadSafeBuilder) WriteString(s string) (int, error) {
14+
tsb.mu.Lock()
15+
defer tsb.mu.Unlock()
16+
17+
return tsb.b.WriteString(s)
18+
}
19+
20+
func (tsb *ThreadSafeBuilder) Write(p []byte) (int, error) {
21+
tsb.mu.Lock()
22+
defer tsb.mu.Unlock()
23+
24+
return tsb.b.Write(p)
25+
}
26+
27+
func (tsb *ThreadSafeBuilder) String() string {
28+
tsb.mu.Lock()
29+
defer tsb.mu.Unlock()
30+
31+
return tsb.b.String()
32+
}
33+
34+
func (tsb *ThreadSafeBuilder) Reset() {
35+
tsb.mu.Lock()
36+
defer tsb.mu.Unlock()
37+
tsb.b.Reset()
38+
}

0 commit comments

Comments
 (0)