Add one more unit test for `---strategy_regexp` (description filter).
// limitations under the License.
package com.google.devtools.build.lib.exec;
-
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
@@ -46,6 +45,8 @@ public class SpawnStrategyRegistryTest {
private static final RegexFilter ELLO_MATCHER =
new RegexFilter(ImmutableList.of("ello"), ImmutableList.of());
+ private static final RegexFilter LLO_MATCHER =
+ new RegexFilter(ImmutableList.of("llo"), ImmutableList.of());
private static void noopEventHandler(Event event) {}
@@ -157,6 +158,7 @@ public class SpawnStrategyRegistryTest {
.containsExactly(strategy2);
}
+ /** If an action matches multiple filters, the latter one gets the priority. */
@Test
public void testMultipleDescriptionFilter() throws Exception {
NoopStrategy strategy1 = new NoopStrategy("1");
@@ -166,9 +168,7 @@ public class SpawnStrategyRegistryTest {
.registerStrategy(strategy1, "foo")
.registerStrategy(strategy2, "bar")
.addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
- .addDescriptionFilter(
- new RegexFilter(ImmutableList.of("ll"), ImmutableList.of()),
- ImmutableList.of("bar"))
+ .addDescriptionFilter(LLO_MATCHER, ImmutableList.of("bar"))
.build();
assertThat(
@@ -178,6 +178,30 @@ public class SpawnStrategyRegistryTest {
.containsExactly(strategy2);
}
+ /**
+ * This demostrate a legacy behavior that the latter description filter doesn't override
+ * preceeding one of same regexp. filter=val_1 filter=val_2 is equivalent to filter=val_2,val_1
+ * TODO: b/196025286 will fix this legacy behavior.
+ */
+ @Test
+ public void testDuplicatedDescriptionFilter() throws Exception {
+ NoopStrategy strategy1 = new NoopStrategy("1");
+ NoopStrategy strategy2 = new NoopStrategy("2");
+ SpawnStrategyRegistry strategyRegistry =
+ SpawnStrategyRegistry.builder()
+ .registerStrategy(strategy1, "foo")
+ .registerStrategy(strategy2, "bar")
+ .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
+ .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar"))
+ .build();
+
+ assertThat(
+ strategyRegistry.getStrategies(
+ createSpawnWithMnemonicAndDescription("", "hello"),
+ SpawnStrategyRegistryTest::noopEventHandler))
+ .containsExactly(strategy2, strategy1);
+ }
+
@Test
public void testMultipleDefaultStrategies() throws Exception {
NoopStrategy strategy1 = new NoopStrategy("1");
@@ -276,6 +300,10 @@ public class SpawnStrategyRegistryTest {
assertThat(exception).hasMessageThat().containsMatch("bar.*Valid.*foo");
}
+ /**
+ * TODO: b/196025286 will gracefully ignore unregistered strategy, which changes the expected
+ * outcome here.
+ */
@Test
public void testDescriptionStrategyNotPresent() {
NoopStrategy strategy1 = new NoopStrategy("1");
@@ -291,6 +319,21 @@ public class SpawnStrategyRegistryTest {
assertThat(exception).hasMessageThat().containsMatch("bar.*Valid.*foo");
}
+ @Test
+ public void testDescriptionStrategyAllNotPresent() {
+ NoopStrategy strategy1 = new NoopStrategy("1");
+ AbruptExitException exception =
+ assertThrows(
+ AbruptExitException.class,
+ () ->
+ SpawnStrategyRegistry.builder()
+ .registerStrategy(strategy1, "foo")
+ .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar", "food"))
+ .build());
+
+ assertThat(exception).hasMessageThat().containsMatch("bar.*Valid.*foo");
+ }
+
@Test
public void testDefaultStrategyNotPresent() {
NoopStrategy strategy1 = new NoopStrategy("1");
