fix(tests): one more attempt to fix the erratic test_scheduler.py (#6612)

* debug(test_scheduler): please fail

* fix(tests): use flags instead of globals since cache is not trhead-safe
This commit is contained in:
Rushabh Mehta 2018-12-12 14:09:50 +05:30 committed by GitHub
parent f4fc85eb87
commit 0f5f04b409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View file

@ -17,6 +17,10 @@ def clear_user_cache(user=None):
"defaults", "user_permissions", "home_page", "linked_with",
"desktop_icons", 'portal_menu_items')
# this will automatically reload the global cache
# so it is important to clear this first
clear_notifications(user)
if user:
for name in groups:
cache.hdel(name, user)
@ -28,8 +32,6 @@ def clear_user_cache(user=None):
clear_defaults_cache()
clear_global_cache()
clear_notifications(user)
def clear_global_cache():
from frappe.website.render import clear_cache as clear_website_cache

View file

@ -3,14 +3,14 @@ from __future__ import unicode_literals
from unittest import TestCase
from dateutil.relativedelta import relativedelta
from frappe.utils.scheduler import (enqueue_applicable_events, restrict_scheduler_events_if_dormant,
get_enabled_scheduler_events, disable_scheduler_on_expiry)
get_enabled_scheduler_events, disable_scheduler_on_expiry)
from frappe import _dict
from frappe.utils.background_jobs import enqueue
from frappe.utils import now_datetime, today, add_days, add_to_date
from frappe.limits import update_limits, clear_limit
import frappe
import json, time
import time
def test_timeout():
'''This function needs to be pickleable'''
@ -49,12 +49,12 @@ class TestScheduler(TestCase):
frappe.flags.enabled_events = None
def test_enabled_events_day_change(self):
val = json.dumps(["daily", "daily_long", "weekly", "weekly_long",
"monthly", "monthly_long"])
frappe.db.set_global('enabled_scheduler_events', val)
# TEMP for debug: this test fails randomly
print('Setting enabled_scheduler_events {0}'.format(val))
# use flags instead of globals as this test fails intermittently
# the root cause has not been identified but the culprit seems cache
# since cache is mutable, it maybe be changed by a parallel process
frappe.flags.enabled_events = ["daily", "daily_long", "weekly", "weekly_long",
"monthly", "monthly_long"]
# maintain last_event and next_event on different days
next_event = now_datetime().replace(hour=0, minute=0, second=0, microsecond=0)
@ -65,6 +65,8 @@ class TestScheduler(TestCase):
self.assertTrue("all" in frappe.flags.ran_schedulers)
self.assertFalse("hourly" in frappe.flags.ran_schedulers)
frappe.flags.enabled_events = None
def test_restrict_scheduler_events(self):
frappe.set_user("Administrator")