Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java =================================================================== RCS file: /usr/local/cvsroot/TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java,v diff -u -r1.25.2.10 -r1.25.2.11 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java 14 Dec 2016 18:51:21 -0000 1.25.2.10 +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java 15 Dec 2016 11:29:41 -0000 1.25.2.11 @@ -30,8 +30,9 @@ import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.TreeMap; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -96,6 +97,7 @@ private static final String SCRATCHIE_IS_LEADER_SUBSTRING = "isUserLeader=true"; private static final Pattern SCRATCHIE_TOOL_SESSION_ID_PATTERN = Pattern.compile("toolSessionID=' \\+ (\\d+)\\)"); private static final String SCRATCHIE_FINISH_SESSION_SUBSTRING = "return finishSession()"; + private static final Set SCRATCHIE_FINISHED_TOOL_CONTENT = new TreeSet(); private static final String CHAT_FINISH_SUBSTRING = "/lams/tool/lachat11/learning.do"; private static final int CHAT_REPLIES = 3; @@ -645,6 +647,7 @@ private WebResponse handleToolScratchie(WebResponse resp) throws SAXException, IOException { String asText = resp.getText(); String finishURL = null; + // check if scratchie is not finished already if (!asText.contains(SCRATCHIE_FINISH_SESSION_SUBSTRING)) { // check if current user is the leader boolean isLeader = asText.contains(MockLearner.SCRATCHIE_IS_LEADER_SUBSTRING); @@ -725,11 +728,10 @@ if (!m.find()) { throw new TestHarnessException("Could not find tool session ID in Scratchie Tool"); } - String toolSessionID = m.group(1); + Long toolSessionID = Long.valueOf(m.group(1)); String websocketURL = test.getTestSuite().getTargetServer().replace("http", "ws") + "/lams/tool/lascrt11/learningWebsocket?toolSessionID=" + toolSessionID; String sessionID = wc.getCookieJar().getCookieValue("JSESSIONID"); - AtomicBoolean close = new AtomicBoolean(); WebsocketClient websocketClient = new WebsocketClient(websocketURL, sessionID, new MessageHandler.Whole() { @Override @@ -739,16 +741,17 @@ try { JSONObject responseJSON = new JSONObject(message); if (responseJSON.optBoolean("close")) { - close.set(true); + // mark the activity as finished for everyone + SCRATCHIE_FINISHED_TOOL_CONTENT.add(toolSessionID); } } catch (Exception e) { log.error("JSON exception in Scratchie " + toolSessionID, e); } } }); - while (!close.get()) { - MockLearner.log.debug(username + " waiting for leader to finish scratchie"); + while (!SCRATCHIE_FINISHED_TOOL_CONTENT.contains(toolSessionID)) { + MockLearner.log.debug("Waiting for leader to finish scratchie"); delay(); }