Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCR-2816 fix mcrxml metadata manager test on windows #2089

Draft
wants to merge 14 commits into
base: 2023.06.x
Choose a base branch
from
97 changes: 19 additions & 78 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,25 @@ name: test

on: [ push, pull_request ]

env:
MAVEN_OPTS: -Xmx1024M -Xss128M
GECKODRIVER_VERSION: 0.27.0

jobs:
build:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin

- name: Fetch Geckodriver cache
id: geckodriver-cache
uses: actions/cache@v2
with:
path: ~/geckodriver
key: ${{ env.GECKODRIVER_VERSION }}

- name: Fetch Geckodriver
if: steps.geckodriver-cache.outputs.cache-hit != 'true'
run: |
mkdir ~/geckodriver
curl -L https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux64.tar.gz | \
tar -C ~/geckodriver/ -xzvf-

- name: Set up test dependencies
run: |
# PPA by Mozilla for ESR releases
sudo add-apt-repository ppa:mozillateam/ppa

sudo apt update
sudo apt install firefox-esr chromium-browser chromium-chromedriver dbus-x11

# Selenium wants to run non-ESR FF
sudo rm -rf /usr/lib/firefox/
sudo ln -s firefox-esr /usr/lib/firefox
sudo ln -s firefox-esr /usr/lib/firefox/firefox
firefox --version

~/geckodriver/geckodriver --version
echo "${HOME}/geckodriver" >> $GITHUB_PATH

- name: Restore Maven cache
uses: skjolber/maven-cache-github-action@v1
with:
step: restore

- name: Build
run: |
export $(dbus-launch)
mkdir ~/tmp
export TMPDIR=~/tmp
export FIREFOX_BIN=$(which firefox-esr)
export SELENIUM_BROWSER=firefox

mvn -B -Plocal-testing,!standard-with-extra-repos clean install -Dlog4j.configurationFile=$PWD/ci/log4j2.xml -T2
mvn -P!standard-with-extra-repos -B javadoc:javadoc

- name: Upload logs on build failure
if: failure()
uses: actions/upload-artifact@v2
with:
name: test-results
path: |
./**/surefire-reports
./**/failsafe-reports
./**/screenshots
./**/*error*.log
./**/*test.log
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
with:
jdk-matrix: '["17"]'
ff-jdk: '17'
ff-os: 'ubuntu-22.04'
ff-site-run: false
ff-goal: '-Plocal-testing,!standard-with-extra-repos -D"log4j.configurationFile"="$GITHUB_WORKSPACE/ci/log4j2.xml" verify'
verify-goal: '-P !standard-with-extra-repos verify'
failure-upload-path: |
./**/surefire-reports
./**/failsafe-reports
./**/screenshots
./**/*error*.log
./**/*test.log
matrix-exclude: >
[
{"os": "macOS-latest"}
]

- name: Save Maven cache
uses: skjolber/maven-cache-github-action@v1
with:
step: save
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ public void setUp() throws Exception {
"<object id=\"MCR_document_00000001\"/>".getBytes(StandardCharsets.UTF_8), new Date());
}

@Override
@After
public void tearDown() throws Exception {
for (File projectDir : getStoreBaseDir().toFile().listFiles()) {
for (File typeDir : projectDir.listFiles()) {
Files.walkFileTree(typeDir.toPath(), MCRRecursiveDeleter.instance());
typeDir.mkdir();
}
}
for (File projectDir : getSvnBaseDir().toFile().listFiles()) {
for (File typeDir : projectDir.listFiles()) {
Files.walkFileTree(typeDir.toPath(), MCRRecursiveDeleter.instance());
typeDir.mkdir();
SVNRepositoryFactory.createLocalRepository(typeDir, true, false);
}
}
super.tearDown();
}

static Document getDocument(InputStream in) throws JDOMException, IOException {
try {
return SAX_BUILDER.build(in);
Expand Down
12 changes: 9 additions & 3 deletions mycore-ifs/src/test/java/org/mycore/common/MCRIFSCopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
import org.junit.Test;
import org.mycore.datamodel.metadata.MCRDerivate;
import org.mycore.datamodel.metadata.MCRMetadataManager;
Expand Down Expand Up @@ -97,9 +98,14 @@ public void create() throws Exception {

@Override
public void tearDown() throws Exception {
MCRMetadataManager.delete(derivate);
MCRMetadataManager.delete(root);
super.tearDown();
try {
MCRMetadataManager.delete(derivate);
MCRMetadataManager.delete(root);
} catch (Exception e) {
LogManager.getLogger().warn("Error while removing test data.", e);
} finally {
super.tearDown();
}
}

public static void copy(String from, String to, MCRDerivate derivate) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.AccessDeniedException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void testRegister() throws IOException {
}

@Test
public void testFiles() throws IOException {
public void testFiles() throws IOException, InterruptedException {
Path file = derivateRoot.resolve("File.txt");
Assert.assertTrue(register.getEntries().isEmpty());
Files.createFile(file);
Expand All @@ -126,7 +127,17 @@ public void testFiles() throws IOException {
Assert.assertEquals(1, register.getEntries().size());
Assert.assertEquals(1, countEvents(MCREvent.EventType.UPDATE));
register.clear();
Files.delete(file);
//Windows fails to delete file here
try {
Files.delete(file);
} catch (AccessDeniedException ade) {
LogManager.getLogger().warn("Error while deleting " + file, ade);
for (int i = 0; i < 5; i++) {
LogManager.getLogger().info("Try #" + (i + 1));
Thread.sleep(5000);
Files.deleteIfExists(file);
}
}
Assert.assertEquals(1, register.getEntries().size());
Assert.assertEquals(1, countEvents(MCREvent.EventType.DELETE));
register.clear();
Expand Down