-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/TR-5854/Detect delivery concurrency #522
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1216a8c
feat: add a plugin for detecting concurrent deliveries opened in the …
jsconan 7c072a5
feat: add a store for the session sequence number
jsconan 53d22ea
feat: use the sequence store for detecting session concurrency
jsconan e387ea0
feat: disable everythuing when a concurrency is deteced
jsconan 41e71f8
test: unit test the sequenceStore
jsconan 6478d8a
test: unit test the plugin preventConcurrency
jsconan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2023 (original work) Open Assessment Technologies SA ; | ||
*/ | ||
import context from 'context'; | ||
import loggerFactory from 'core/logger'; | ||
import __ from 'i18n'; | ||
import states from 'taoQtiTest/runner/config/states'; | ||
import { getSequenceNumber, getSequenceStore } from 'taoQtiTest/runner/services/sequenceStore'; | ||
import pluginFactory from 'taoTests/runner/plugin'; | ||
|
||
const logger = loggerFactory('taoQtiTest/runner/plugins/controls/session/preventConcurrency'); | ||
|
||
const FEATURE_FLAG = 'FEATURE_FLAG_PAUSE_CONCURRENT_SESSIONS'; | ||
|
||
/** | ||
* Test Runner Control Plugin : detect concurrent deliveries launched from the same user session. | ||
*/ | ||
export default pluginFactory({ | ||
name: 'preventConcurrency', | ||
|
||
/** | ||
* Initializes the plugin (called during runner's init) | ||
*/ | ||
init() { | ||
const testRunner = this.getTestRunner(); | ||
const options = testRunner.getOptions(); | ||
const skipPausedAssessmentDialog = !!options.skipPausedAssessmentDialog; | ||
|
||
return Promise.all([getSequenceNumber(testRunner), getSequenceStore()]).then( | ||
([sequenceNumber, sequenceStore]) => | ||
sequenceStore.setSequenceNumber(sequenceNumber).then(() => { | ||
testRunner | ||
.on('tick', () => { | ||
if (context.featureFlags[FEATURE_FLAG]) { | ||
return sequenceStore.getSequenceNumber().then(lastSequenceNumber => { | ||
if (lastSequenceNumber !== sequenceNumber) { | ||
testRunner.off('tick'); | ||
testRunner.trigger('disabletools'); | ||
testRunner.trigger('disablenav'); | ||
testRunner.trigger('disableitem'); | ||
testRunner.trigger('concurrency'); | ||
return Promise.reject(); | ||
} | ||
}); | ||
} | ||
}) | ||
.on('concurrency', () => { | ||
logger.warn( | ||
`The sequence number has changed. Was another delivery opened in the same browser?` | ||
); | ||
testRunner.trigger('leave', { | ||
code: states.testSession.suspended, | ||
message: __( | ||
'A concurrent delivery has been detected. Please use the last open session. The present window can be closed.' | ||
), | ||
skipExitMessage: skipPausedAssessmentDialog | ||
}); | ||
}); | ||
}) | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2023 (original work) Open Assessment Technologies SA ; | ||
*/ | ||
import store from 'core/store'; | ||
|
||
const STORE_ID = 'current'; | ||
const SEQUENCE_NUMBER = 'sequence'; | ||
|
||
export default { | ||
/** | ||
* Creates a store for the sequence number for the session. | ||
* @returns {Promise} - Resolved with the store API. | ||
*/ | ||
getSequenceStore() { | ||
return store(STORE_ID).then(sequenceStore => ({ | ||
/** | ||
* Stores the sequence number for the session. | ||
* @param {string} sequenceNumber - The new sequence number to set for the session. | ||
* @returns {Promise} - Resolved once the sequence number has been stored. | ||
*/ | ||
setSequenceNumber(sequenceNumber) { | ||
return sequenceStore.setItem(SEQUENCE_NUMBER, sequenceNumber); | ||
}, | ||
|
||
/** | ||
* Reads the sequence number for the session from the storage. | ||
* @returns {Promise<string>} - Resolved with the sequence number for the session. | ||
*/ | ||
getSequenceNumber() { | ||
return sequenceStore.getItem(SEQUENCE_NUMBER); | ||
} | ||
})); | ||
}, | ||
|
||
/** | ||
* Creates a sequence number for the test runner. | ||
* @returns {Promise<string>} - Resolved with sequence number for the session. | ||
*/ | ||
getSequenceNumber(testRunner) { | ||
return testRunner | ||
.getTestStore() | ||
.getStorageIdentifier() | ||
.then(storeId => `${storeId}-${Date.now()}`); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
test/plugins/controls/preventConcurrency/mocks/sequenceStore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
define(function () { | ||
('use strict'); | ||
|
||
let sequenceNumber = ''; | ||
|
||
return { | ||
getSequenceStore() { | ||
return Promise.resolve({ | ||
setSequenceNumber(seq) { | ||
sequenceNumber = seq; | ||
return Promise.resolve(); | ||
}, | ||
|
||
getSequenceNumber() { | ||
return Promise.resolve(sequenceNumber); | ||
} | ||
}); | ||
}, | ||
|
||
getSequenceNumber(testRunner) { | ||
return Promise.resolve(testRunner.sequenceNumber); | ||
}, | ||
|
||
setSequenceNumber(seq) { | ||
sequenceNumber = seq; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Test Runner Plugins - preventConcurrency</title> | ||
<script type="text/javascript" src="/environment/require.js"></script> | ||
<script type="text/javascript"> | ||
require(['/environment/config.js'], function() { | ||
require(['qunitEnv'], function() { | ||
requirejs.config({ | ||
paths: { | ||
'taoQtiTest/runner/services/sequenceStore': '/test/plugins/controls/preventConcurrency/mocks/sequenceStore' | ||
} | ||
}); | ||
require(['taoQtiTest/test/runner/plugins/controls/preventConcurrency/test'], function() { | ||
QUnit.start(); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gabrielfs7 the translation scanner will take care of it, from the consumer extension, as usual (say taoQtiTest)