Skip to content

Commit

Permalink
Merge pull request #37632 from code-dot-org/invalidate-script-cache
Browse files Browse the repository at this point in the history
Invalidate script cache on test machine during ui tests
  • Loading branch information
davidsbailey committed Nov 3, 2020
2 parents 83d918d + 17d135a commit 1649206
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
7 changes: 7 additions & 0 deletions dashboard/app/controllers/test_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def create_script
render json: {script_name: script.name, lesson_id: lesson.id}
end

# invalidate the specified script from the script cache, so that it will be
# reloaded from the DB the next time it is requested.
def invalidate_script
Script.remove_from_cache(params[:script_name])
head :ok
end

def destroy_script
script = Script.find_by!(name: params[:script_name])
script.destroy
Expand Down
4 changes: 4 additions & 0 deletions dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ def self.get_family_from_cache(family_name)
end
end

def self.remove_from_cache(script_name)
script_cache.delete(script_name) if script_cache
end

def self.get_script_family_redirect_for_user(family_name, user: nil, locale: 'en-US')
return nil unless family_name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ Scenario: Save changes to a script
And element "#script_text" contains text "level 'Applab test'"
And I scroll the ".btn-primary" element into view
And I type "lesson 'temp-lesson', display_name: 'Temp Lesson'\nlevel 'Standalone_Artist_1'\nlevel 'Standalone_Artist_2'\n" into "#script_text"
And I remove the temp script from the cache
And I click selector ".btn-primary" to load a new page
And I wait until element "#script-title" is visible

Then element ".uitest-bubble" contains text "1"

# this check is disabled because the script cache is enabled on the test machine,
# which means that during a DTT the rails server may return a cached copy of the
# script on the script overview page which only has bubble "1" but not bubble "2".
# TODO(dave): re-enable once we have a way to update/invalidate the cache on
# script save.

# And element ".uitest-bubble" contains text "2"
And element ".uitest-bubble" contains text "2"

And I delete the temp script and lesson

Expand Down
8 changes: 8 additions & 0 deletions dashboard/test/ui/features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,14 @@ def wait_for_jquery
}
end

Given (/^I remove the temp script from the cache$/) do
browser_request(
url: '/api/test/invalidate_script',
method: 'POST',
body: {script_name: @temp_script_name}
)
end

Given(/^I delete the temp script and lesson$/) do
browser_request(
url: '/api/test/destroy_script',
Expand Down

0 comments on commit 1649206

Please sign in to comment.