Skip to content

Commit 9cd9220

Browse files
authored
Use atomic.Bool for OnFlushEnd callback test (#827)
The OnFlushStart/OnFlushEnd context-propagation check used a plain bool. On Windows the flush can complete within a single clock tick, so use atomic.Bool to avoid a data race flagged by CI. Bump cluster.wait-ready sleep from 2s to 3s to reduce false negatives on slower CI runners. Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent 6347ab2 commit 9cd9220

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
157157

158158
### Fixed
159159

160-
- Fix bulk indexer HTML-escaping `_id` and `routing` values containing `<`, `>`, or `&` characters, causing OpenSearch to store escaped values (e.g., `\u003croot_account\u003e` stored instead of `<root_account>`), leading to duplicate documents, unreachable data on read-by-ID paths, and potential shard routing mismatches. Present since the `json.Marshal` migration in 2021 (commit `3da59092`). Replace `json.Marshal` with `json.NewEncoder` + `SetEscapeHTML(false)` in `opensearchutil.worker.writeMeta` and `opensearchutil.JSONReader`; replace per-worker `aux []byte` with `sync.Pool`-backed `*bytes.Buffer`; add table-driven test coverage for `writeMeta` edge cases ([#824](https://github.com/opensearch-project/opensearch-go/pull/824))
160+
- Fix bulk indexer HTML-escaping `_id` and `routing` values containing `<`, `>`, or `&` characters, causing OpenSearch to store escaped values (e.g., `\u003croot_account\u003e` stored instead of `<root_account>`), leading to duplicate documents, unreachable data on read-by-ID paths, and potential shard routing mismatches. Present since the `json.Marshal` migration in 2021 (commit `3da59092`). Replace `json.Marshal` with `json.NewEncoder` + `SetEscapeHTML(false)` in `opensearchutil.worker.writeMeta` and `opensearchutil.JSONReader`; replace per-worker `aux []byte` with `sync.Pool`-backed `*bytes.Buffer`; add table-driven test coverage for `writeMeta` edge cases and refactor remaining `TestBulkIndexer` subtests to table-driven `require`-based style ([#824](https://github.com/opensearch-project/opensearch-go/pull/824))
161161
- Fix pool replacement orphaning resurrection goroutines during node discovery, causing connections to become permanently dead with no active health checker ([#786](https://github.com/opensearch-project/opensearch-go/pull/786))
162162
- Extract `newMultiServerPoolFromClientWithLock` as single source of truth for Client-to-pool settings propagation ([#786](https://github.com/opensearch-project/opensearch-go/pull/786))
163163
- Fix discovery pool wipe when all cluster nodes time out during `/_nodes/http` fan-out: parse `_nodes` metadata envelope and return `errDiscoveryEmpty` when `successful == 0`, preserving the existing connection pool for retry ([#821](https://github.com/opensearch-project/opensearch-go/pull/821))

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ cluster.wait-ready: ## Poll cluster until health status is green or yellow
437437
else \
438438
printf "\033[33m⋯ Waiting for cluster to respond (attempt $$ATTEMPT/$$MAX_ATTEMPTS)\033[0m\n"; \
439439
ATTEMPT=$$((ATTEMPT + 1)); \
440-
sleep 2; \
440+
sleep 3; \
441441
continue; \
442442
fi; \
443443
fi; \
@@ -464,7 +464,7 @@ cluster.wait-ready: ## Poll cluster until health status is green or yellow
464464
printf "\033[33m⋯ Waiting for cluster to respond (attempt $$ATTEMPT/$$MAX_ATTEMPTS)\033[0m\n"; \
465465
fi; \
466466
ATTEMPT=$$((ATTEMPT + 1)); \
467-
sleep 2; \
467+
sleep 3; \
468468
done; \
469469
printf "\033[31m✗ Cluster failed to become ready after $$MAX_ATTEMPTS attempts\033[0m\n"; \
470470
printf "\033[2m\n--- Diagnostic Information ---\033[0m\n"; \

opensearchutil/bulk_indexer_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ func TestBulkIndexerCallbacks(t *testing.T) {
708708
}}})
709709
flushIndex := testutil.MustUniqueString(t, "test-flush")
710710

711-
var flushEndCalled bool
711+
var flushEndCalled atomic.Bool
712712
bi, _ := NewBulkIndexer(BulkIndexerConfig{
713713
Client: client,
714714
Index: flushIndex,
@@ -717,7 +717,7 @@ func TestBulkIndexerCallbacks(t *testing.T) {
717717
},
718718
OnFlushEnd: func(ctx context.Context) {
719719
if v, ok := ctx.Value(contextKey("flushing")).(bool); ok && v {
720-
flushEndCalled = true
720+
flushEndCalled.Store(true)
721721
}
722722
},
723723
})
@@ -729,7 +729,7 @@ func TestBulkIndexerCallbacks(t *testing.T) {
729729
require.NoError(t, bi.Close(context.Background()))
730730

731731
require.Equal(t, uint64(1), bi.Stats().NumAdded, "NumAdded")
732-
require.True(t, flushEndCalled, "OnFlushEnd should have been called with the context from OnFlushStart")
732+
require.True(t, flushEndCalled.Load(), "OnFlushEnd should have been called with the context from OnFlushStart")
733733
},
734734
},
735735
{

0 commit comments

Comments
 (0)