After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 748422 - thetvdb: Make it possible to hit only cache
thetvdb: Make it possible to hit only cache
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
git master
Other Linux
: Normal normal
: ---
Assigned To: grilo-maint
grilo-maint
Depends on: 748550
Blocks:
 
 
Reported: 2015-04-24 16:36 UTC by Bastien Nocera
Modified: 2015-08-29 15:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY (4.47 KB, patch)
2015-04-26 17:31 UTC, Victor Toso
none Details | Review
thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY (2.33 KB, patch)
2015-04-27 20:32 UTC, Victor Toso
committed Details | Review
tests: use temporary database on thetvdb tests (1.64 KB, patch)
2015-04-27 20:32 UTC, Victor Toso
none Details | Review
tests: thetvdb test cache-only (4.79 KB, patch)
2015-04-27 20:33 UTC, Victor Toso
none Details | Review
tests: use temporary database on thetvdb tests (1.63 KB, patch)
2015-05-01 22:08 UTC, Victor Toso
committed Details | Review
tests: improve internals of thetvdb resolve shows (4.12 KB, patch)
2015-05-01 22:09 UTC, Victor Toso
none Details | Review
tests: thetvdb tests cache-only (1.74 KB, patch)
2015-05-01 22:09 UTC, Victor Toso
none Details | Review
tests: new function to reset test environment (2.52 KB, patch)
2015-08-28 19:50 UTC, Victor Toso
committed Details | Review
tests: improve internals of thetvdb resolve shows (5.51 KB, patch)
2015-08-28 19:51 UTC, Victor Toso
committed Details | Review
tests: thetvdb tests cache-only (1.79 KB, patch)
2015-08-28 19:51 UTC, Victor Toso
committed Details | Review

Description Bastien Nocera 2015-04-24 16:36:06 UTC
When doing lookups, it might be useful to avoid hitting the network, and only process from the cache. This would be flagged with the GRL_RESOLVE_FAST_ONLY cap.
Comment 1 Victor Toso 2015-04-26 17:31:12 UTC
Created attachment 302388 [details] [review]
thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY

The patch includes a new unit test for cache-only.
Comment 2 Bastien Nocera 2015-04-27 09:22:08 UTC
Review of attachment 302388 [details] [review]:

::: src/thetvdb/grl-thetvdb.c
@@ +1508,3 @@
   os->lang = get_pref_language (GRL_THETVDB_SOURCE (source));
   os->fetched_web = FALSE;
+  os->cache_only = (res & GRL_RESOLVE_FAST_ONLY) ? TRUE : FALSE;

os->cache_only = (res & GRL_RESOLVE_FAST_ONLY);
should be enough here.

::: tests/thetvdb/test_thetvdb_resolve_shows.c
@@ +197,3 @@
 
+  g_test_add_func ("/thetvdb/resolve/normal/shows", test_shows_normal);
+  g_test_add_func ("/thetvdb/resolve/fast-only/shows", test_shows_fast_only);

How do you know it's only hitting the cache here?

The best way to do this would be to:
- do the lookup with an empty DB and cache only, check that it fails
- do the lookup with a series name
- and figure out a way to make the network lookup fail, and do the lookup again
Comment 3 Victor Toso 2015-04-27 09:32:38 UTC
Thanks for the review,

(In reply to Bastien Nocera from comment #2)
> Review of attachment 302388 [details] [review] [review]:
> 
> ::: src/thetvdb/grl-thetvdb.c
> @@ +1508,3 @@
>    os->lang = get_pref_language (GRL_THETVDB_SOURCE (source));
>    os->fetched_web = FALSE;
> +  os->cache_only = (res & GRL_RESOLVE_FAST_ONLY) ? TRUE : FALSE;
> 
> os->cache_only = (res & GRL_RESOLVE_FAST_ONLY);
> should be enough here.

Sure.

> 
> ::: tests/thetvdb/test_thetvdb_resolve_shows.c
> @@ +197,3 @@
>  
> +  g_test_add_func ("/thetvdb/resolve/normal/shows", test_shows_normal);
> +  g_test_add_func ("/thetvdb/resolve/fast-only/shows",
> test_shows_fast_only);
> 
> How do you know it's only hitting the cache here?
> 
> The best way to do this would be to:
> - do the lookup with an empty DB and cache only, check that it fails
> - do the lookup with a series name
> - and figure out a way to make the network lookup fail, and do the lookup
> again

Okay, I'll fix the test.

- Regarding the database, is it enough to set XDG_DATA_HOME on the unit test in order to avoid using the default database?
Comment 4 Bastien Nocera 2015-04-27 09:33:52 UTC
(In reply to Victor Toso from comment #3)
> Thanks for the review,
> 
> (In reply to Bastien Nocera from comment #2)
> > Review of attachment 302388 [details] [review] [review] [review]:
> > 
> > ::: src/thetvdb/grl-thetvdb.c
> > @@ +1508,3 @@
> >    os->lang = get_pref_language (GRL_THETVDB_SOURCE (source));
> >    os->fetched_web = FALSE;
> > +  os->cache_only = (res & GRL_RESOLVE_FAST_ONLY) ? TRUE : FALSE;
> > 
> > os->cache_only = (res & GRL_RESOLVE_FAST_ONLY);
> > should be enough here.
> 
> Sure.
> 
> > 
> > ::: tests/thetvdb/test_thetvdb_resolve_shows.c
> > @@ +197,3 @@
> >  
> > +  g_test_add_func ("/thetvdb/resolve/normal/shows", test_shows_normal);
> > +  g_test_add_func ("/thetvdb/resolve/fast-only/shows",
> > test_shows_fast_only);
> > 
> > How do you know it's only hitting the cache here?
> > 
> > The best way to do this would be to:
> > - do the lookup with an empty DB and cache only, check that it fails
> > - do the lookup with a series name
> > - and figure out a way to make the network lookup fail, and do the lookup
> > again
> 
> Okay, I'll fix the test.
> 
> - Regarding the database, is it enough to set XDG_DATA_HOME on the unit test
> in order to avoid using the default database?

It should be enough, yes.
Comment 5 Victor Toso 2015-04-27 20:32:36 UTC
Created attachment 302482 [details] [review]
thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY
Comment 6 Victor Toso 2015-04-27 20:32:54 UTC
Created attachment 302483 [details] [review]
tests: use temporary database on thetvdb tests
Comment 7 Victor Toso 2015-04-27 20:33:08 UTC
Created attachment 302484 [details] [review]
tests: thetvdb test cache-only

cache-only test with empty database and with filled database but without
network
Comment 8 Victor Toso 2015-04-27 20:34:47 UTC
Forgot to include that this test changes depends on Grilo patch/bug: https://bugzilla.gnome.org/show_bug.cgi?id=74855
Comment 9 Victor Toso 2015-04-27 20:35:27 UTC
Sorry, wrong url:
https://bugzilla.gnome.org/show_bug.cgi?id=748550
Comment 10 Bastien Nocera 2015-04-28 09:22:39 UTC
Review of attachment 302482 [details] [review]:

Looks good.
Comment 11 Bastien Nocera 2015-04-28 09:24:50 UTC
Review of attachment 302483 [details] [review]:

::: tests/thetvdb/test_thetvdb_utils.c
@@ +33,3 @@
   GrlRegistry *registry;
   GError *error = NULL;
+  const gchar *tmp_dir = g_get_tmp_dir ();

Use g_mkdtemp() to create a separate directory inside the temporary directory.

@@ +70,3 @@
+
+  /* Remove database so it doesn't affect other tests */
+  db_path = g_build_filename (g_get_tmp_dir (),

You'll need to keep using the same temp dir as in the setup. You can make your temp XDG_DATA_HOME a global variable for that.
Comment 12 Bastien Nocera 2015-04-28 09:28:24 UTC
Review of attachment 302484 [details] [review]:

::: tests/thetvdb/test_thetvdb_resolve_shows.c
@@ +24,3 @@
 #include <grilo.h>
 
+/* Returns FALSE if can't find tvdb-id; TRUE otherwise */

"Returns whether it could find tvdb-id"

@@ +87,3 @@
+  }
+
+  *imdb = g_strdup (grl_data_get_string (GRL_DATA (video), imdb_key));

This should be in a separate patch.

@@ +203,3 @@
+test_shows_fast_only_full_db(void)
+{
+  const gchar *mock = g_getenv ("GRL_NET_MOCKED");

You'll need to make a copy of it here, because it's going to get overwritten in the g_setenv() call below.
Comment 13 Victor Toso 2015-04-28 09:35:53 UTC
Thanks for the review!

(In reply to Bastien Nocera from comment #11)
> Review of attachment 302483 [details] [review] [review]:
> 
> ::: tests/thetvdb/test_thetvdb_utils.c
> @@ +33,3 @@
>    GrlRegistry *registry;
>    GError *error = NULL;
> +  const gchar *tmp_dir = g_get_tmp_dir ();
> 
> Use g_mkdtemp() to create a separate directory inside the temporary
> directory.

Okay!

> 
> @@ +70,3 @@
> +
> +  /* Remove database so it doesn't affect other tests */
> +  db_path = g_build_filename (g_get_tmp_dir (),
> 
> You'll need to keep using the same temp dir as in the setup. You can make
> your temp XDG_DATA_HOME a global variable for that.

Okay!


(In reply to Bastien Nocera from comment #12)
> Review of attachment 302484 [details] [review] [review]:
> 
> ::: tests/thetvdb/test_thetvdb_resolve_shows.c
> @@ +24,3 @@
>  #include <grilo.h>
>  
> +/* Returns FALSE if can't find tvdb-id; TRUE otherwise */
> 
> "Returns whether it could find tvdb-id"

Thanks!

> 
> @@ +87,3 @@
> +  }
> +
> +  *imdb = g_strdup (grl_data_get_string (GRL_DATA (video), imdb_key));
> 
> This should be in a separate patch.

I'll split.

> 
> @@ +203,3 @@
> +test_shows_fast_only_full_db(void)
> +{
> +  const gchar *mock = g_getenv ("GRL_NET_MOCKED");
> 
> You'll need to make a copy of it here, because it's going to get overwritten
> in the g_setenv() call below.

Indeed. Thanks
Comment 14 Victor Toso 2015-05-01 22:07:18 UTC
Comment on attachment 302482 [details] [review]
thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY

Attachment 302482 [details] pushed as eaa64e9 - thetvdb: enable cache-only on GRL_RESOLVE_FAST_ONLY
Comment 15 Victor Toso 2015-05-01 22:08:50 UTC
Created attachment 302742 [details] [review]
tests: use temporary database on thetvdb tests
Comment 16 Victor Toso 2015-05-01 22:09:07 UTC
Created attachment 302743 [details] [review]
tests: improve internals of thetvdb resolve shows

This apply last commit changes to have each test with its own thetvdb
database and also improves test by:
- having resolve flag as parameter;
- possibilty to fail test when expected;
Comment 17 Victor Toso 2015-05-01 22:09:29 UTC
Created attachment 302744 [details] [review]
tests: thetvdb tests cache-only

cache-only test with empty database and with filled database but without
network
Comment 18 Bastien Nocera 2015-05-02 11:54:06 UTC
Review of attachment 302742 [details] [review]:

Looks fine otherwise.

::: tests/thetvdb/test_thetvdb_utils.c
@@ +77,3 @@
+  g_remove (db_path);
+  g_free (db_path);
+  g_clear_pointer (&tmp_dir, g_free);

You should probably remove the grilo-plugins subdir, and the tmp_dir with g_remove() as well.
Comment 19 Bastien Nocera 2015-05-02 11:54:31 UTC
Review of attachment 302743 [details] [review]:

Sure.
Comment 20 Bastien Nocera 2015-05-02 11:55:09 UTC
Review of attachment 302744 [details] [review]:

Looks good!
Comment 21 Victor Toso 2015-05-02 12:08:25 UTC
(In reply to Bastien Nocera from comment #18)
> Review of attachment 302742 [details] [review] [review]:
> 
> Looks fine otherwise.
> 
> ::: tests/thetvdb/test_thetvdb_utils.c
> @@ +77,3 @@
> +  g_remove (db_path);
> +  g_free (db_path);
> +  g_clear_pointer (&tmp_dir, g_free);
> 
> You should probably remove the grilo-plugins subdir, and the tmp_dir with
> g_remove() as well.

After running the test I have gvfs cache there as well and g_remove() only works for empty dirs. So I thought that removing the database would be enough instead of tracking everything created and removing each one of them.

I'll create a rmdir using GFileEnumerator then :-)
Comment 22 Bastien Nocera 2015-05-02 12:12:48 UTC
Disable gvfs in the tests instead?
Comment 23 Bastien Nocera 2015-05-02 12:13:32 UTC
(In reply to Bastien Nocera from comment #22)
> Disable gvfs in the tests instead?

GIO_USE_VFS=0 as an envvar IIRC.
Comment 24 Victor Toso 2015-05-02 12:32:25 UTC
GIO_USE_VFS=local worked, thanks
Comment 25 Bastien Nocera 2015-08-25 16:31:00 UTC
Comment on attachment 302742 [details] [review]
tests: use temporary database on thetvdb tests

Attachment 302742 [details] pushed as b4cf71a - tests: use temporary database on thetvdb tests
Comment 26 Victor Toso 2015-08-28 19:50:59 UTC
Created attachment 310219 [details] [review]
tests: new function to reset test environment

With commit b4cf71a18de08825006ed7e7c3b8545e736b1839 we are using
temporary database for thetvdb tests. The goal of this patch is a way to
reset test environment by removing the database and re-loading the
plugin. If a test need a clean environment, it can call
test_reset_thetvdb ().
Comment 27 Victor Toso 2015-08-28 19:51:19 UTC
Created attachment 310220 [details] [review]
tests: improve internals of thetvdb resolve shows

This apply last commit changes to have each test with its own thetvdb
database and also improves test by:
- having resolve flag as parameter;
- possibilty to fail test when expected;
Comment 28 Victor Toso 2015-08-28 19:51:38 UTC
Created attachment 310221 [details] [review]
tests: thetvdb tests cache-only

cache-only test with empty database and with filled database but without
network
Comment 29 Bastien Nocera 2015-08-29 12:50:32 UTC
Review of attachment 310219 [details] [review]:

Looks fine.
Comment 30 Bastien Nocera 2015-08-29 12:52:20 UTC
Review of attachment 310220 [details] [review]:

Sure.
Comment 31 Bastien Nocera 2015-08-29 12:52:33 UTC
Review of attachment 310221 [details] [review]:

Looks good.
Comment 32 Victor Toso 2015-08-29 15:37:29 UTC
Attachment 310219 [details] pushed as ef77cb7 - tests: new function to reset test environment
Attachment 310220 [details] pushed as 9169323 - tests: improve internals of thetvdb resolve shows
Attachment 310221 [details] pushed as 9b67d69 - tests: thetvdb tests cache-only