How not to make async task tests

Before moving to Dramatiq I used to use Celery. And when it came to unit testing the first thing I added to my code was:


At the time I thought this was the best way. But after a lot of trial and error (and mainly because of Dramatiq, which I couldn’t find an eager mode) I found out that the eager mindset is wrong when it comes to unit testing.

By using eager mode I was treating my async tasks as sync and the views or methods that call those tasks need to run successfully without the async task.

So, in my opinion the best way to test this is to do something like (django with rest framework):

Read More

Dramatiq: alternative to Celery

Ever since I started doing web development async tasks were a thing. You can’t send an email synchronously and risk leaving the suer hanging. The solution was Celery. I used celery in a lot of projects. Simple websites to full single page applications.

But celery started to feel bulky, heavy and slugish. One of the major problems I’ve had with celery is the sheer complexity of the code. It’s impossible to dig into it.

When I heard about Dramatiq I was very intrigued. It promisses things that Celery never had (like prioritization of tasks) and probably will never have. After trying it out I can say that it is really good. Declaring and sending tasks is as easy as ever, having only to annotate a method and calling task.send.

Dramatiq also has middlewares so you can enable and disable features really easily (like error reporting, message retries, prioritization and so on).

import dramatiq
def count_words(url):
    response = requests.get(url)
    count = len(response.text.split(" "))
    print(f"There are {count} words at {url!r}.")

Read More

Celeste is an amazing game

Just finished my first playthrough of Celeste on my Nintendo Switch. What an amazing game. The mechanics are simple enough that you have no problem picking the game up. But the difficulty curve is so well leveled that you just want to keep playing to get better. Also the fact that dying is instant allows to replay every screen very fast until you get it just right.

On top of all of this you get a heartfelt story about Madeleine that is struggling with depression. The way she has to deal with her inner self to be able to live with her issues is an inspiring story. Truly a game that everyone should experience.

Read More