Skip to content

Commit bec556d

Browse files
committed
Fix test setup to properly free context (#130787)
1 parent 45d48ea commit bec556d

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
@@ -329,12 +329,6 @@ tests:
329329
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
330330
method: test {p0=transform/transforms_start_stop/Test start/stop/start continuous transform}
331331
issue: https://github.com/elastic/elasticsearch/issues/126755
332-
- class: org.elasticsearch.search.SearchServiceSingleNodeTests
333-
method: testBeforeShardLockDuringShardCreate
334-
issue: https://github.com/elastic/elasticsearch/issues/126812
335-
- class: org.elasticsearch.search.SearchServiceSingleNodeTests
336-
method: testLookUpSearchContext
337-
issue: https://github.com/elastic/elasticsearch/issues/126813
338332
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
339333
method: test {p0=transform/transforms_stats/Test get multiple transform stats where one does not have a task}
340334
issue: https://github.com/elastic/elasticsearch/issues/126863

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;
@@ -1255,8 +1256,22 @@ public void testBeforeShardLockDuringShardCreate() {
12551256
TestShardRouting.newShardRouting(
12561257
new ShardId(indexService.index(), 0),
12571258
randomAlphaOfLength(5),
1258-
randomBoolean(),
1259-
ShardRoutingState.INITIALIZING
1259+
true,
1260+
ShardRoutingState.INITIALIZING,
1261+
RecoverySource.EmptyStoreRecoverySource.INSTANCE
1262+
),
1263+
indexService.getIndexSettings().getSettings()
1264+
);
1265+
assertEquals(1, service.getActiveContexts());
1266+
1267+
boolean primary = randomBoolean();
1268+
service.beforeIndexShardCreated(
1269+
TestShardRouting.newShardRouting(
1270+
new ShardId(indexService.index(), 0),
1271+
randomAlphaOfLength(5),
1272+
primary,
1273+
ShardRoutingState.INITIALIZING,
1274+
primary ? RecoverySource.ExistingStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
12601275
),
12611276
indexService.getIndexSettings().getSettings()
12621277
);

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
@@ -131,6 +131,16 @@ public static ShardRouting newShardRouting(ShardId shardId, String currentNodeId
131131
return newShardRouting(shardId, currentNodeId, primary, state, ShardRouting.Role.DEFAULT);
132132
}
133133

134+
public static ShardRouting newShardRouting(
135+
ShardId shardId,
136+
String currentNodeId,
137+
boolean primary,
138+
ShardRoutingState state,
139+
RecoverySource recoverySource
140+
) {
141+
return newShardRouting(shardId, currentNodeId, primary, state, recoverySource, ShardRouting.Role.DEFAULT);
142+
}
143+
134144
public static ShardRouting newShardRouting(
135145
ShardId shardId,
136146
String currentNodeId,
@@ -154,6 +164,30 @@ public static ShardRouting newShardRouting(
154164
);
155165
}
156166

167+
public static ShardRouting newShardRouting(
168+
ShardId shardId,
169+
String currentNodeId,
170+
boolean primary,
171+
ShardRoutingState state,
172+
RecoverySource recoverySource,
173+
ShardRouting.Role role
174+
) {
175+
assertNotEquals(ShardRoutingState.RELOCATING, state);
176+
return new ShardRouting(
177+
shardId,
178+
currentNodeId,
179+
null,
180+
primary,
181+
state,
182+
recoverySource,
183+
buildUnassignedInfo(state),
184+
buildRelocationFailureInfo(state),
185+
buildAllocationId(state),
186+
ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE,
187+
role
188+
);
189+
}
190+
157191
public static ShardRouting newShardRouting(
158192
String index,
159193
int shardId,

0 commit comments

Comments
 (0)