How to fix deadlocks with tests?

48 views
Skip to first unread message

Joshua Gardner

unread,
Oct 27, 2023, 12:21:29 PM10/27/23
to django...@googlegroups.com
I'm experiencing deadlocks in my production application occasionally. I'm
using MySQL. Some of these deadlocks are due to insufficient indexing,
and I'd like to fix this with some test-driven development.

How can I write tests that exercise the application concurrently, and
could be used to replicate the deadlocks and then fix them? I use
pytest-django and I use MySQL in my tests; there's a lot of raw SQL and
even some views and stored procedures (😱) in this application and some
of those may be culprits too of course.

I suppose my main question is "how to test bugs that occur due to
concurrency?"

-Josh

Chetan Ganji

unread,
Oct 27, 2023, 2:01:57 PM10/27/23
to django...@googlegroups.com
Hey,
This problem seems to be unique. There might not be a standard solution. 

https://github.com/jazzband/django-silk

You can replicate the prod environment to local and profile it using django silk.
If you can somehow manage to reproduce the bug and find the timestamp when it happened; 
you can find out the sql queries that were running around that timestamp. 
You might be able to find out the root cause of the problem and fix it.

I am not 100% sure if it will help. But it is worth a try. 
I hope it helps you.

Thanks!


Regards,
Chetan Ganji
+91-900-483-4183


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/874jicca6t.fsf%40jgardner.tech.
Reply all
Reply to author
Forward
0 new messages