Skip to content

Commit 258fdcc

Browse files
authored
Fix test setup to properly free context (elastic#130787) (elastic#130835)
1 parent 1d31ea2 commit 258fdcc

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,6 @@ tests:
432432
- class: org.elasticsearch.action.RejectionActionIT
433433
method: testSimulatedSearchRejectionLoad
434434
issue: https://github.com/elastic/elasticsearch/issues/125901
435-
- class: org.elasticsearch.search.SearchServiceSingleNodeTests
436-
method: testBeforeShardLockDuringShardCreate
437-
issue: https://github.com/elastic/elasticsearch/issues/126812
438-
- class: org.elasticsearch.search.SearchServiceSingleNodeTests
439-
method: testLookUpSearchContext
440-
issue: https://github.com/elastic/elasticsearch/issues/126813
441435
- class: org.elasticsearch.test.index.IndexVersionUtilsTests
442436
method: testIndexCompatibleVersionMatches
443437
issue: https://github.com/elastic/elasticsearch/issues/120760

server/src/test/java/org/elasticsearch/search/SearchServiceSingleNodeTests.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.action.support.WriteRequest;
4545
import org.elasticsearch.client.internal.Client;
4646
import org.elasticsearch.cluster.metadata.IndexMetadata;
47+
import org.elasticsearch.cluster.routing.RecoverySource;
4748
import org.elasticsearch.cluster.routing.ShardRouting;
4849
import org.elasticsearch.cluster.routing.ShardRoutingState;
4950
import org.elasticsearch.cluster.routing.TestShardRouting;
@@ -1259,8 +1260,22 @@ public void testBeforeShardLockDuringShardCreate() {
12591260
TestShardRouting.newShardRouting(
12601261
new ShardId(indexService.index(), 0),
12611262
randomAlphaOfLength(5),
1262-
randomBoolean(),
1263-
ShardRoutingState.INITIALIZING
1263+
true,
1264+
ShardRoutingState.INITIALIZING,
1265+
RecoverySource.EmptyStoreRecoverySource.INSTANCE
1266+
),
1267+
indexService.getIndexSettings().getSettings()
1268+
);
1269+
assertEquals(1, service.getActiveContexts());
1270+
1271+
boolean primary = randomBoolean();
1272+
service.beforeIndexShardCreated(
1273+
TestShardRouting.newShardRouting(
1274+
new ShardId(indexService.index(), 0),
1275+
randomAlphaOfLength(5),
1276+
primary,
1277+
ShardRoutingState.INITIALIZING,
1278+
primary ? RecoverySource.ExistingStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
12641279
),
12651280
indexService.getIndexSettings().getSettings()
12661281
);

test/framework/src/main/java/org/elasticsearch/cluster/routing/TestShardRouting.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public static ShardRouting newShardRouting(String index, int shardId, String cur
127127
return newShardRouting(new ShardId(index, IndexMetadata.INDEX_UUID_NA_VALUE, shardId), currentNodeId, primary, state);
128128
}
129129

130+
public static ShardRouting newShardRouting(
131+
ShardId shardId,
132+
String currentNodeId,
133+
boolean primary,
134+
ShardRoutingState state,
135+
RecoverySource recoverySource
136+
) {
137+
return newShardRouting(shardId, currentNodeId, primary, state, recoverySource, ShardRouting.Role.DEFAULT);
138+
}
139+
130140
public static ShardRouting newShardRouting(ShardId shardId, String currentNodeId, boolean primary, ShardRoutingState state) {
131141
assertNotEquals(ShardRoutingState.RELOCATING, state);
132142
return new ShardRouting(
@@ -144,6 +154,30 @@ public static ShardRouting newShardRouting(ShardId shardId, String currentNodeId
144154
);
145155
}
146156

157+
public static ShardRouting newShardRouting(
158+
ShardId shardId,
159+
String currentNodeId,
160+
boolean primary,
161+
ShardRoutingState state,
162+
RecoverySource recoverySource,
163+
ShardRouting.Role role
164+
) {
165+
assertNotEquals(ShardRoutingState.RELOCATING, state);
166+
return new ShardRouting(
167+
shardId,
168+
currentNodeId,
169+
null,
170+
primary,
171+
state,
172+
recoverySource,
173+
buildUnassignedInfo(state),
174+
buildRelocationFailureInfo(state),
175+
buildAllocationId(state),
176+
ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE,
177+
role
178+
);
179+
}
180+
147181
public static ShardRouting newShardRouting(
148182
String index,
149183
int shardId,

0 commit comments

Comments
 (0)