Comments (4)
What version of Django, postgresql do you use?
Can you provide full traceback and detail explonation how to reproduce the bug?
Why did you run apscheduler tests with postgresql connection? Or it affects your project tests? If it is, I will be glad if you provide example of failing test.
from django-apscheduler.
Versions
Django==2.0.4
PostgreSQL 10.1, compiled by Visual C++ build 1800, 64-bit
Traceback
Testing started at 5:18 PM ...
...\Scripts\python.exe "...\pycharm\django_test_manage.py" test accounts.tests ...\Django\project
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
Destroying test database for alias 'default'...
Traceback (most recent call last):
File "...\project\Lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.OperationalError: database "test_projectdb" is being accessed by other users
DETAIL: There is 1 other session using the database.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "...\helpers\pycharm\django_test_manage.py", line 168, in <module>
utility.execute()
File "...\helpers\pycharm\django_test_manage.py", line 142, in execute
_create_command().run_from_argv(self.argv)
File "...\project\Lib\site-packages\django\core\management\commands\test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "...\project\Lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "...\project\Lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "...\pycharm\django_test_manage.py", line 104, in handle
failures = TestRunner(test_labels, **options)
File "...\pycharm\django_test_runner.py", line 255, in run_tests
extra_tests=extra_tests, **options)
File "...\pycharm\django_test_runner.py", line 156, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
File "...\project\Lib\site-packages\django\test\runner.py", line 604, in run_tests
self.teardown_databases(old_config)
File "...\project\Lib\site-packages\django\test\runner.py", line 577, in teardown_databases
keepdb=self.keepdb,
File "...\project\Lib\site-packages\django\test\utils.py", line 299, in teardown_databases
connection.creation.destroy_test_db(old_name, verbosity, keepdb)
File "...\project\Lib\site-packages\django\db\backends\base\creation.py", line 259, in destroy_test_db
self._destroy_test_db(test_database_name, verbosity)
File "...\project\Lib\site-packages\django\db\backends\base\creation.py", line 276, in _destroy_test_db
% self.connection.ops.quote_name(test_database_name))
File "...\project\Lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "...\project\Lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "...\project\Lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "...\project\Lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "...\project\Lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.OperationalError: database "test_projectdb" is being accessed by other users
DETAIL: There is 1 other session using the database.
Process finished with exit code 1
On additional test runs, the test database has to be destroyed manually.
Testing started at 5:33 PM ...
...\Scripts\python.exe "...\pycharm\django_test_manage.py" test accounts.tests ...
Creating test database for alias 'default'...
Got an error creating the test database: database "test_projectdb" already exists
Type 'yes' if you would like to try deleting the test database 'test_projectdb', or 'no' to cancel: yes
Destroying old test database for alias 'default'...
System check identified no issues (0 silenced).
Destroying test database for alias 'default'...
I wanted to include some integration tests for views that call scheduler.add_job(). Postgresql is used for both testing and live. In hindsight, it's probably overkill to test for task persistence when it's all going to be destroyed along with the database.
I'm currently using the MemoryJobStore when running tests, which is probably a better idea (see below).
Created a schedules.py file in an app module:
import sys
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.schedulers.background import BackgroundScheduler
from django_apscheduler.jobstores import DjangoJobStore, register_events
scheduler = BackgroundScheduler()
if 'test' in sys.argv:
scheduler.add_jobstore(MemoryJobStore(), 'default')
else: # pragma: no cover
scheduler.add_jobstore(DjangoJobStore(), 'default')
register_events(scheduler)
scheduler.start()
from django-apscheduler.
Awesome, thank you. I'll take a look in the week
from django-apscheduler.
Sorted out how to do integration tests with tasks. Same settings to use MemoryJobStore in testing. In your StaticLiveServerTestCase subclass (or LiveServerTestCase), add to your tearDown method:
def tearDown(self):
...
scheduler.shutdown(wait=10)
After tinkering with different settings, I found it a requirement to set the wait kwarg high enough for all connections to be closed, else the test running returns the error.
from django-apscheduler.
Related Issues (20)
- PytzUsageWarning on Startup HOT 3
- Missing migration
- Feat: Add management command to clean up job execution table HOT 2
- How to associate django_apscheduler_djangojob with my own model by ForeignKey HOT 1
- Job automatically disappeared in random time HOT 2
- Feature: simplified closing of old db connections HOT 4
- Client number building up leading to fatal error HOT 1
- skipped: maximum number of running instances reached
- cron function that is running over 15 seconds is not working HOT 1
- DB error executing '_get_jobs' ((2013, 'Lost connection to MySQL server during query')). Retrying with a new DB connection... HOT 3
- Add @util.close_old_connections in the _get_jobs(self, **filters) funtion for the DB connection
- AttributeError("'zoneinfo.ZoneInfo' object has no attribute 'localize'") and 'dict' object has no attribute 'has_header'
- ModuleNotFoundError: No module named 'backports'
- how to forbid change_permission and delete_permission... HOT 2
- Scheduler goes idle or does not execute jobs at all HOT 1
- transaction.atomic() problem with DATABASE_ROUTERS HOT 2
- django-apscheduler (0.6.2) not working with psycopg2-binary (2.9.4 and up)
- Trigger scheduled job to be executed manually HOT 2
- Unapplying Migrations Fails
- DjangoJobStore Randomly Deletes Jobs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-apscheduler.