[grilo/mocking] net: Permit unthrottled mock sessions.



commit b9044d08230f347dd9f9c512a06f64f1909c6567
Author: Mathias Hasselmann <mathias openismus com>
Date:   Thu Oct 11 22:16:05 2012 +0200

    net: Permit unthrottled mock sessions.

 doc/grilo/plugins-testing.xml |    6 ++++++
 libs/net/grl-net-mock.c       |    9 +++++++++
 libs/net/grl-net-mock.h       |    1 +
 libs/net/grl-net-wc.c         |    5 +++--
 4 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/doc/grilo/plugins-testing.xml b/doc/grilo/plugins-testing.xml
index 217157e..fb21052 100644
--- a/doc/grilo/plugins-testing.xml
+++ b/doc/grilo/plugins-testing.xml
@@ -107,6 +107,12 @@ $ export GRL_DEBUG="registry:*"
     </para>
 
     <para>
+      To enable mocking set the environment variable GRL_NET_MOCKED.
+      If that variable is set to the value "unthrottled", request throttling
+      is disabled too.
+    </para>
+
+    <para>
       For configuring mock answers, a simple .ini file is used. The file is
       split into a "default" section and one section per URL.
     </para>
diff --git a/libs/net/grl-net-mock.c b/libs/net/grl-net-mock.c
index 1ea162a..328164c 100644
--- a/libs/net/grl-net-mock.c
+++ b/libs/net/grl-net-mock.c
@@ -52,6 +52,15 @@ is_mocked (void)
           && g_ascii_strcasecmp(env, "false");
 }
 
+gboolean
+is_unthrottled (void)
+{
+  /* Reusing the GRL_NET_MOCKED variable to ensure that throttling
+   * only can be disabled in mocked sessions. */
+  const char *const env = g_getenv ("GRL_NET_MOCKED");
+  return env && g_ascii_strcasecmp(env, "unthrottled") == 0;
+}
+
 void
 get_url_mocked (GrlNetWc *self,
                 const char *url,
diff --git a/libs/net/grl-net-mock.h b/libs/net/grl-net-mock.h
index da18b38..e71ffba 100644
--- a/libs/net/grl-net-mock.h
+++ b/libs/net/grl-net-mock.h
@@ -26,6 +26,7 @@
 #include "grl-net-wc.h"
 
 gboolean is_mocked (void);
+gboolean is_unthrottled (void);
 
 void get_url_mocked (GrlNetWc *self,
                      const char *url,
diff --git a/libs/net/grl-net-wc.c b/libs/net/grl-net-wc.c
index 36e681b..e167895 100644
--- a/libs/net/grl-net-wc.c
+++ b/libs/net/grl-net-wc.c
@@ -325,7 +325,8 @@ get_url (GrlNetWc *self,
 
   g_get_current_time (&now);
 
-  if ((now.tv_sec - priv->last_request.tv_sec) > priv->throttling) {
+  if ((now.tv_sec - priv->last_request.tv_sec) > priv->throttling
+          || is_unthrottled ()) {
     if (is_mocked ())
       get_url_mocked (self, url, headers, result, cancellable);
     else
@@ -335,7 +336,7 @@ get_url (GrlNetWc *self,
     return;
   }
 
-  GRL_DEBUG ("delaying web request");
+  GRL_DEBUG ("delaying web request %d", is_unthrottled ());
 
   /* closure */
   c = g_new (struct request_clos, 1);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]