Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit b7d64a9

Browse files
Merge pull request code-dot-org#36586 from code-dot-org/dtp_candidate_099b95ed
DTP (Test > Production: 099b95e)
2 parents fba527c + 099b95e commit b7d64a9

File tree

10 files changed

+46
-16
lines changed

10 files changed

+46
-16
lines changed

apps/src/code-studio/clientState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import {trySetSessionStorage} from '../utils';
66
import cookies from 'js-cookie';
7+
// Note: sessionStorage is not shared between tabs.
78
var sessionStorage = window.sessionStorage;
89

910
import {mergeActivityResult} from './activityUtils';

apps/src/code-studio/initApp/loadApp.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import ReactDOM from 'react-dom';
55
import {TestResults} from '@cdo/apps/constants';
66
import {getStore} from '../redux';
7-
import {mergeProgress} from '../progressRedux';
7+
import {clearProgress, mergeProgress} from '../progressRedux';
88
import {SignInState} from '@cdo/apps/templates/currentUserRedux';
99
import {setVerified} from '@cdo/apps/code-studio/verifiedTeacherRedux';
1010
import {
@@ -33,6 +33,7 @@ import queryString from 'query-string';
3333
import * as imageUtils from '@cdo/apps/imageUtils';
3434
import trackEvent from '../../util/trackEvent';
3535
import msg from '@cdo/locale';
36+
import _ from 'lodash';
3637

3738
// Max milliseconds to wait for last attempt data from the server
3839
var LAST_ATTEMPT_TIMEOUT = 5000;
@@ -51,8 +52,22 @@ const SHARE_IMAGE_NAME = '_share_image.png';
5152
* @param {Object<number, TestResult>} serverProgress Mapping from levelId to TestResult
5253
*/
5354
function mergeProgressData(scriptName, serverProgress) {
55+
if (!serverProgress) {
56+
return;
57+
}
5458
const store = getStore();
55-
store.dispatch(mergeProgress(serverProgress));
59+
60+
// The server returned progress. This is the source of truth.
61+
// Note: Changes to the progressRedux also update the sessionStorage,
62+
// so this will clear and update the sessionStorage too.
63+
store.dispatch(clearProgress());
64+
store.dispatch(
65+
mergeProgress(
66+
_.mapValues(serverProgress, level =>
67+
level.submitted ? TestResults.SUBMITTED_RESULT : level.result
68+
)
69+
)
70+
);
5671

5772
Object.keys(serverProgress).forEach(levelId => {
5873
// Write down new progress in sessionStorage
@@ -392,8 +407,7 @@ function loadAppAsync(appOptions) {
392407
appOptions.disableSocialShare = data.disableSocialShare;
393408

394409
// Merge progress from server (loaded via AJAX)
395-
const serverProgress = data.progress || {};
396-
mergeProgressData(appOptions.scriptName, serverProgress);
410+
mergeProgressData(appOptions.scriptName, data.progress);
397411

398412
if (!lastAttemptLoaded) {
399413
if (data.lastAttempt) {
@@ -435,6 +449,11 @@ function loadAppAsync(appOptions) {
435449
}
436450

437451
const store = getStore();
452+
453+
// Note: We aren't guaranteed that currentUser.signInState will have been set at this point.
454+
// It gets set on document.ready. However, it is highly unlikely that the server will return
455+
// a response before document.ready is triggered. So far, this hasn't caused problems, so not
456+
// worrying about this for now.
438457
const signInState = store.getState().currentUser.signInState;
439458
if (signInState === SignInState.SignedIn) {
440459
progress.showDisabledBubblesAlert();

apps/src/code-studio/progressRedux.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const userProgressFromServer = (state, dispatch, userId = null) => {
304304
// If we have a userId, we can clear any progress in redux and request all progress
305305
// from the server.
306306
if (userId) {
307-
dispatch({type: CLEAR_PROGRESS});
307+
dispatch(clearProgress());
308308
}
309309

310310
return $.ajax({
@@ -393,6 +393,10 @@ export const initProgress = ({
393393
isFullProgress
394394
});
395395

396+
export const clearProgress = () => ({
397+
type: CLEAR_PROGRESS
398+
});
399+
396400
export const mergeProgress = levelProgress => ({
397401
type: MERGE_PROGRESS,
398402
levelProgress

cookbooks/Berksfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ GRAPH
9696
sudo-user (>= 0.0.0)
9797
cdo-cloudwatch-agent (0.1.1)
9898
aws_cloudwatch (>= 0.0.0)
99-
cdo-github-access (0.1.9)
99+
cdo-github-access (0.1.10)
100100
cdo-home-ubuntu (0.1.5)
101101
cdo-i18n (0.0.0)
102102
apt (~> 2.6.0)

cookbooks/cdo-github-access/files/default/gitconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
[user]
44
name = Continuous Integration
55
email = dev@code.org
6+
7+
# https://git-scm.com/docs/git-gc#_configuration
8+
[gc]
9+
# Make git gc --auto return immediately and run in background if the system supports it. Default is true.
10+
#
11+
# Set false to prevent gc --auto from being interrupted by server shutdown, leaving behind large temp files.
12+
autoDetach = false

cookbooks/cdo-github-access/metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
license 'All rights reserved'
55
description 'Installs/Configures cdo-github-access'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '0.1.9'
7+
version '0.1.10'

dashboard/app/controllers/api_controller.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,8 @@ def user_progress_for_stage
430430
user_level = current_user.last_attempt(level, script)
431431
level_source = user_level.try(:level_source).try(:data)
432432

433-
response[:progress] = current_user.
434-
user_levels.
435-
by_stage(stage).
436-
pluck(:level_id, :best_result).
437-
to_h
433+
# Temporarily return the full set of progress so we can overwrite what the sessionStorage changed
434+
response[:progress] = summarize_user_progress(script, current_user)[:levels]
438435

439436
if user_level
440437
response[:lastAttempt] = {

dashboard/test/controllers/api_controller_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,11 @@ class ApiControllerTest < ActionController::TestCase
618618
stage_position: 1,
619619
level_position: 1
620620
}
621+
result = {"status" => "perfect", "result" => 100}
621622
assert_response :success
622623
body = JSON.parse(response.body)
623624
assert_equal nil, body['disableSocialShare']
624-
assert_equal 100, body['progress'][level.id.to_s]
625+
assert_equal result, body['progress'][level.id.to_s]
625626
assert_equal 'level source', body['lastAttempt']['source']
626627

627628
assert_equal(

dashboard/test/integration/db_query_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def setup
5151
level: level.id
5252
)
5353

54-
assert_cached_queries(7) do
54+
assert_cached_queries(10) do
5555
get user_progress_path,
5656
headers: {'HTTP_USER_AGENT': 'test'}
5757
assert_response :success

dashboard/test/ui/features/hour_of_code/hour_of_code_signed_in.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ Scenario: Failing at puzzle 6, refreshing puzzle 6, bubble should show up as att
4040
When element "#runButton" is visible
4141
Then I verify progress in the header of the current page is "attempted" for level 6
4242

43+
# The server should be the source of truth. If we have a stale read, that means we haven't saved the user progress.
4344
Scenario: Async progress write followed by a stale read
4445
Given I am on "http://studio.code.org/hoc/20?noautoplay=true"
4546
And I wait for the page to fully load
4647
And I verify progress in the header of the current page is "not_tried" for level 20
4748
Then mark the current level as completed on the client
4849
And I wait for 3 seconds
4950
And I reload the page
50-
And I verify progress in the header of the current page is "perfect" for level 20
51+
And I verify progress in the header of the current page is "not_tried" for level 20
5152
And I wait for 3 seconds
5253
And I navigate to the course page for "hourofcode"
53-
And I verify progress for stage 1 level 20 is "perfect"
54+
And I verify progress for stage 1 level 20 is "not_tried"
5455

5556
Scenario: Progress on the server that is not on the client
5657
Given I am on "http://studio.code.org/hoc/20?noautoplay=true"

0 commit comments

Comments
 (0)