Skip to content

Commit 685a11e

Browse files
committed
Fix flakiness in tests across modules
1 parent a43b995 commit 685a11e

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

lti/lti-common/src/test/org/sakaiproject/lti/util/SakaiKeySetUtilTest.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,21 @@ public void testRotationAndKeySet()
161161

162162
String keySetJSON = SakaiKeySetUtil.getKeySet();
163163
assertNotNull(keySetJSON);
164-
assertTrue(keySetJSON.contains("{\"keys\":[{\"kty\":"));
165-
assertTrue(keySetJSON.contains(",\"alg\":\"RS256\""));
164+
166165
JSONObject ks_json = LTIUtil.parseJSONObject(keySetJSON);
166+
assertNotNull(ks_json);
167+
167168
JSONArray keys = (JSONArray) ks_json.get("keys");
169+
assertNotNull(keys);
168170
assertEquals(keys.size(), 3);
171+
169172
for(int i=0; i< keys.size(); i++) {
170173
JSONObject key = (JSONObject) keys.get(i);
171174
assertNotNull(key);
172-
String kid = (String) key.get("kid");
173-
assertNotNull(kid);
174-
String n = (String) key.get("n");
175-
assertNotNull(n);
175+
assertNotNull(key.get("kid"));
176+
assertNotNull(key.get("n"));
177+
assertNotNull(key.get("kty"));
178+
assertNotNull(key.get("alg"));
176179
}
177180

178181
// Test the expiration of the previous key
@@ -184,11 +187,22 @@ public void testRotationAndKeySet()
184187

185188
keySetJSON = SakaiKeySetUtil.getKeySet();
186189
assertNotNull(keySetJSON);
187-
assertTrue(keySetJSON.contains("{\"keys\":[{\"kty\":"));
188-
assertTrue(keySetJSON.contains(",\"alg\":\"RS256\""));
190+
189191
ks_json = LTIUtil.parseJSONObject(keySetJSON);
192+
assertNotNull(ks_json);
193+
190194
keys = (JSONArray) ks_json.get("keys");
195+
assertNotNull(keys);
191196
assertEquals(keys.size(), 2);
197+
198+
for(int i=0; i< keys.size(); i++) {
199+
JSONObject key = (JSONObject) keys.get(i);
200+
assertNotNull(key);
201+
assertNotNull(key.get("kid"));
202+
assertNotNull(key.get("n"));
203+
assertNotNull(key.get("kty"));
204+
assertNotNull(key.get("alg"));
205+
}
192206
}
193207

194208
}

lti/tsugi-util/src/test/org/tsugi/lti13/LTI13ObjectTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.tsugi.lti13.objects.OpenIDClientRegistration;
2020
import org.tsugi.lti13.objects.LTIToolConfiguration;
2121

22+
import com.fasterxml.jackson.databind.JsonNode;
2223
import com.fasterxml.jackson.databind.ObjectMapper;
2324

2425
import org.tsugi.lti13.LTICustomVars;
@@ -243,7 +244,11 @@ public void testfour() throws com.fasterxml.jackson.core.JsonProcessingException
243244
ObjectMapper mapper = JacksonUtil.getLaxObjectMapper();
244245
OpenIDClientRegistration ocr1 = mapper.readValue(first, OpenIDClientRegistration.class);
245246
OpenIDClientRegistration ocr2 = mapper.readValue(second, OpenIDClientRegistration.class);
247+
246248
assertTrue(ocr1.prettyPrintLog().contains("[email protected]"));
247-
assertEquals(ocr1.prettyPrintLog(), ocr2.prettyPrintLog());
249+
250+
JsonNode expected = mapper.readTree(ocr1.prettyPrintLog());
251+
JsonNode actual = mapper.readTree(ocr2.prettyPrintLog());
252+
assertEquals(expected, actual);
248253
}
249254
}

rwiki/rwiki-impl/impl/src/test/uk/ac/cam/caret/sakai/rwiki/component/service/impl/test/RWikiObjectServiceImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package uk.ac.cam.caret.sakai.rwiki.component.service.impl.test;
2424

2525
import java.util.HashSet;
26+
import java.util.LinkedHashSet;
2627

2728
import uk.ac.cam.caret.sakai.rwiki.component.service.impl.RWikiObjectServiceImpl;
2829
import uk.ac.cam.caret.sakai.rwiki.model.RWikiCurrentObjectImpl;
@@ -82,7 +83,7 @@ public void testExtractReferencesExtractReferencesTwoReference() {
8283
public void testExtractReferencesExtractReferencesTooLong() {
8384
StringBuffer sb;
8485
rwco = new RWikiCurrentObjectImpl();
85-
HashSet<String> hs = new HashSet<String>();
86+
HashSet<String> hs = new LinkedHashSet<>();
8687

8788
hs.add(longString(3990));
8889
sb = rwosi.extractReferences(rwco, hs);

samigo/samigo-services/src/test/org/sakaiproject/tool/assessment/services/ItemCancellationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.util.ArrayList;
2727
import java.util.Arrays;
28+
import java.util.Comparator;
2829
import java.util.List;
2930
import java.util.concurrent.atomic.AtomicLong;
3031
import java.util.stream.Collectors;
@@ -212,6 +213,11 @@ private void assertItemCancellation(ItemDataIfc[] testItems, ItemDataIfc[] cance
212213

213214
// Convert "saved" items to array
214215
ItemDataIfc[] savedItems = savedItemList.toArray(new ItemDataIfc[savedItemList.size()]);
216+
217+
// Ensure deterministic order before comparing
218+
Comparator<ItemDataIfc> byId = Comparator.comparing(ItemDataIfc::getItemId);
219+
Arrays.sort(savedItems, byId);
220+
Arrays.sort(cancelledTestItems, byId);
215221

216222
// Test if we have same number of items
217223
Assert.assertEquals(cancelledTestItems.length, savedItems.length);

0 commit comments

Comments
 (0)