Skip to content

Commit

Permalink
Fix flaky test SelectionIT#selectBlame
Browse files Browse the repository at this point in the history
If the console operator was used for both operators, the blame
  would select more punishments than intended.
  • Loading branch information
A248 committed Apr 21, 2021
1 parent a5947ae commit bd3fced
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* LibertyBans
* Copyright © 2021 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* LibertyBans is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/>
* and navigate to version 3 of the GNU Affero General Public License.
*/

package space.arim.libertybans.it.resolver;

/**
* When used on a parameter provided by {@code RandomOperatorResolver},
* prevents the console operator from being used
*/
public @interface NotConsole {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package space.arim.libertybans.it.resolver;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

Expand All @@ -36,8 +35,8 @@ public class RandomOperatorResolver extends TypeBasedParameterResolver<Operator>
@Override
public Operator resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
Random random = ThreadLocalRandom.current();
if (random.nextBoolean()) {
if (!parameterContext.isAnnotated(NotConsole.class)
&& ThreadLocalRandom.current().nextBoolean()) {
return ConsoleOperator.INSTANCE;
}
return PlayerOperator.of(UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

import space.arim.libertybans.it.resolver.NotConsole;
import space.arim.omnibus.util.concurrent.CentralisedFuture;

import space.arim.libertybans.api.Operator;
Expand Down Expand Up @@ -189,7 +190,7 @@ public void selectHistoricalBansMutes(@DontInject @SingularPunishment Punishment

@TestTemplate
public void selectBlame(@DontInject Victim victim1, @DontInject Victim victim2,
@DontInject Operator operator1, @DontInject Operator operator2) {
@DontInject Operator operator1, @DontInject @NotConsole Operator operator2) {
Punishment banFromOp1 = getPunishment(
draftBuilder(PunishmentType.BAN, victim1, "banhammer").operator(operator1));
Punishment warnFromOp2 = getPunishment(
Expand Down

0 comments on commit bd3fced

Please sign in to comment.