Page MenuHomePhabricator
Paste P7936

(An Untitled Masterwork)
ActivePublic

Authored by Halfak on Dec 20 2018, 4:54 PM.
Tags
None
Referenced Files
F27688097:
Dec 20 2018, 4:54 PM
Subscribers
None
[10:05:59] <halfak> o/ Amir1
[10:06:06] <halfak> Added some notes to https://github.com/wikimedia/ores/pull/306
[10:06:08] <Amir1> hey
[10:06:14] <Amir1> Already answered all
[10:06:31] <halfak> I think we should pull redis-service out of the unit tests. You should be able to construct the Redis score_cache with a mock Redis connection.
[10:07:02] <Amir1> That's a lot of work
[10:07:08] <Amir1> for little gain
[10:07:15] <halfak> Is it? It seems like mocking two function calls is pretty straightforward
[10:07:19] <halfak> It's standard practice for a reason.
[10:07:30] <halfak> Two function calls: get/set
[10:08:20] <halfak> https://github.com/wikimedia/ores/blob/a80bdfa13bc79a8c68be326379a12f254fa9360e/ores/score_caches/redis.py#L30
[10:08:31] <halfak> https://github.com/wikimedia/ores/blob/a80bdfa13bc79a8c68be326379a12f254fa9360e/ores/score_caches/redis.py#L43
[10:08:33] <halfak> *setex
[10:08:33] * travis-ci (~travis-ci@ec2-54-163-139-160.compute-1.amazonaws.com) has joined
[10:08:34] <travis-ci> wikimedia/ores#1228 (celery_tests - 03208cd : Amir Sarabadani): The build has errored. https://travis-ci.org/wikimedia/ores/builds/470578788
[10:08:34] * travis-ci (~travis-ci@ec2-54-163-139-160.compute-1.amazonaws.com) has left
[10:09:18] <Amir1> the thing is in any case that redis is not available you can just skip all redis by running pytest -m "not redis"
[10:13:19] <Amir1> + how you are going to mock redis in celery tests? I'm writing tests for that too
[10:20:44] <halfak> In all cases, redis just needs get and setex mocked. They are simple key-value set and get patterns so it should be really easy.
[10:21:27] <halfak> I'd say that redis is possibly the easiest thing to mock that I have ever come across.
[10:21:30] <halfak> :P
[10:21:45] * basile is now known as guillom
[10:23:37] <Amir1> yes but how I'm going to inject the mock into celery app?
[10:23:52] <halfak> apps?
[10:24:12] <halfak> Oh I see what you mean. I think celery will need to be mocked.
[10:24:41] <halfak> http://docs.celeryproject.org/en/latest/userguide/testing.html
[10:24:49] <halfak> "To test task behavior in unit tests the preferred method is mocking."
[10:26:12] <halfak> I think you can just run celery in single thread mode too.
[10:26:47] <halfak> This seems relevant: http://docs.celeryproject.org/en/3.1/configuration.html#celery-always-eager