Skip to content

Commit

Permalink
Fix DropImportCommand flaky test
Browse files Browse the repository at this point in the history
Fix DropImportCommand flaky test by ensuring the wait condition is applied to exportable locales only instead of all locales, by reusing the shouldCreateDrop method.

Based on 514d5c2
  • Loading branch information
wadimw committed Oct 3, 2023
1 parent 5fbd960 commit 49b2c50
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ List<String> getBcp47TagsForExportFromParam(Repository repository) throws Comman
return bcp47tags;
}

private boolean shouldCreateDrop(Repository repository) {
protected boolean shouldCreateDrop(Repository repository) {
boolean createDrop = false;
Set<String> Bcp47TagsForTranslation = Sets.newHashSet(getBcp47TagsForExportFromRepository(repository));
Set<String> bcp47TagsForTranslation = Sets.newHashSet(getBcp47TagsForExportFromRepository(repository));
RepositoryStatistic repoStat = repository.getRepositoryStatistic();
if (repoStat != null) {
for (RepositoryLocaleStatistic repoLocaleStat : repoStat.getRepositoryLocaleStatistics()) {
if (Bcp47TagsForTranslation.contains(repoLocaleStat.getLocale().getBcp47Tag()) && repoLocaleStat.getForTranslationCount() > 0L) {
if (bcp47TagsForTranslation.contains(repoLocaleStat.getLocale().getBcp47Tag()) && repoLocaleStat.getForTranslationCount() > 0L) {
createDrop = true;
break;
}
Expand Down
15 changes: 5 additions & 10 deletions cli/src/test/java/com/box/l10n/mojito/cli/CLITestBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.box.l10n.mojito.cli;

import com.box.l10n.mojito.cli.command.L10nJCommander;
import com.box.l10n.mojito.cli.command.RepositoryStatusChecker;
import com.box.l10n.mojito.entity.Locale;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.entity.TMTextUnitVariant;
Expand Down Expand Up @@ -87,7 +88,9 @@ public class CLITestBase extends IOTestBase {
ResttemplateConfig resttemplateConfig;

@Autowired
RepositoryClient repositoryClient;
protected RepositoryClient repositoryClient;

RepositoryStatusChecker repositoryStatusChecker = new RepositoryStatusChecker();

@Autowired
AssetRepository assetRepository;
Expand Down Expand Up @@ -210,15 +213,7 @@ protected void waitForCondition(String failMessage, Supplier<Boolean> condition)
protected void waitForRepositoryToHaveStringsForTranslations(Long repositoryId) throws InterruptedException {
waitForCondition("wait for repository stats to show forTranslationCount > 0 before exporting a drop", () -> {
com.box.l10n.mojito.rest.entity.Repository repository = repositoryClient.getRepositoryById(repositoryId);
RepositoryStatistic repositoryStat = repository.getRepositoryStatistic();
boolean forTranslation = false;
for (RepositoryLocaleStatistic repositoryLocaleStat : repositoryStat.getRepositoryLocaleStatistics()) {
if (repositoryLocaleStat.getForTranslationCount() > 0L) {
forTranslation = true;
}
break;
}
return forTranslation;
return repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(repository);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.box.l10n.mojito.cli.CLITestBase;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.entity.RepositoryStatistic;
import com.box.l10n.mojito.rest.client.AssetClient;
import com.box.l10n.mojito.rest.client.DropClient;
import com.box.l10n.mojito.rest.entity.Asset;
import com.box.l10n.mojito.rest.entity.Drop;
import com.box.l10n.mojito.rest.entity.Page;
import com.box.l10n.mojito.service.repository.RepositoryRepository;
import com.box.l10n.mojito.service.tm.TMImportService;
import static org.junit.Assert.*;
import com.google.common.collect.Sets;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -27,6 +30,9 @@ public class DropExportCommandTest extends CLITestBase {
@Autowired
DropClient dropClient;

@Autowired
RepositoryRepository repositoryRepository;

@Test
public void export() throws Exception {

Expand Down Expand Up @@ -58,7 +64,13 @@ public void exportFullyTranslated() throws Exception {
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");

waitForRepositoryToHaveStringsForTranslations(repository.getId());
waitForCondition("Must have text units that are fully translated", () -> {
RepositoryStatistic repositoryStatistic = repositoryRepository.findOne(repository.getId()).getRepositoryStatistic();
return repositoryStatistic.getUsedTextUnitCount() > 0
&& repositoryStatistic.getRepositoryLocaleStatistics().stream()
.filter(rls -> Sets.newHashSet("fr-FR", "ja-JP").contains(rls.getLocale().getBcp47Tag()))
.allMatch(rls -> rls.getForTranslationCount() == 0);
});

Page<Drop> findAllBefore = dropClient.getDrops(repository.getId(), null, null, null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.box.l10n.mojito.cli.command;

import com.box.l10n.mojito.rest.entity.Repository;

/**
*
* @author garion
*/
public class RepositoryStatusChecker {
public boolean hasStringsForTranslationsForExportableLocales(Repository repository) {
DropExportCommand dropExportCommand = new DropExportCommand();
return dropExportCommand.shouldCreateDrop(repository);
}
}

0 comments on commit 49b2c50

Please sign in to comment.