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

Flaky test fixed #2147

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
Expand All @@ -48,7 +51,6 @@

import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -176,7 +178,7 @@ public void testThrows() throws Exception {
ClassCollector cc = context.get(ClassCollector.class);
assertEquals(2, cc.getServiceClassNames().size());

final Map<String, Class<?>[]> methods = new HashMap<>();
final Map<String, Class<?>[]> methods = new LinkedHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no dependency on ordering anywhere in the test (AFAICT) @Derrick2000 please clarify where the flakyness was observed

methods.put("listRepositories", new Class<?>[] {});
methods.put("createRepository", new Class<?>[] {java.io.IOException.class});
methods.put("deleteRepository",
Expand All @@ -192,7 +194,24 @@ public void testThrows() throws Exception {
} catch (NoSuchMethodException e) {
m = generatedClass.getMethod(entry.getKey(), String.class, String.class);
}
assertArrayEquals(entry.getValue(), m.getExceptionTypes());
ClassLoader classLoader = generatedClass.getClassLoader();
Class<?>[] expectedExceptions = new Class<?>[entry.getValue().length];
for (int i = 0; i < entry.getValue().length; i++) {
expectedExceptions[i] = classLoader.loadClass(entry.getValue()[i].getName());
}

// Compare exception class names
Set<String> expectedExceptionNames = Arrays.stream(expectedExceptions)
.map(Class::getName)
.collect(Collectors.toSet());

Set<String> actualExceptionNames = Arrays.stream(m.getExceptionTypes())
.map(Class::getName)
.collect(Collectors.toSet());

assertEquals("Exceptions for method " + m.getName() + " do not match.",
expectedExceptionNames, actualExceptionNames);

}
}
}
Expand Down
Loading