[grilo/mocking: 21/27] net: Simplify GRL_NET_MOCKED variable



commit 670b93f12f3ad97179c7f7944f49aa410e4bee3b
Author: Mathias Hasselmann <mathias openismus com>
Date:   Sat Oct 20 22:01:42 2012 +0200

    net: Simplify GRL_NET_MOCKED variable
    
    Always set throttling to zero in mocking mode.

 doc/grilo/plugins-testing.xml   |   22 ++--------------
 libs/net/grl-net-mock-private.h |    3 --
 libs/net/grl-net-mock.c         |   52 ++++++++------------------------------
 libs/net/grl-net-wc.c           |    8 +----
 4 files changed, 16 insertions(+), 69 deletions(-)
---
diff --git a/doc/grilo/plugins-testing.xml b/doc/grilo/plugins-testing.xml
index 7bea521..52462fc 100644
--- a/doc/grilo/plugins-testing.xml
+++ b/doc/grilo/plugins-testing.xml
@@ -108,25 +108,9 @@ $ export GRL_DEBUG="registry:*"
 
     <para>
       To enable mocking set the environment variable GRL_NET_MOCKED. The value
-      of this variable is interpreted as colon separated list of configuration
-      settings, e.g. <code>config=mock-my-plugin.ini:throttle=0</code>
-
-      <itemizedlist>
-        <listitem>
-          <varname>config</varname> selects a different file than
-          "grl-mock-data.ini" for configuring mock answers.
-        </listitem>
-
-        <listitem>
-          <varname>throttle</varname> overrides any throttling requests from
-          plugins. Set this variable to zero to disable any throttling.
-        </listitem>
-      </itemizedlist>
-    </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.
+      of this variable is interpreted as path of the mock configuration file to
+      use. This file is a simple .ini file is used which is  The file is split
+      into a "default" section and one section per URL to mock.
     </para>
 
     <programlisting>
diff --git a/libs/net/grl-net-mock-private.h b/libs/net/grl-net-mock-private.h
index 24ce249..2a3cea4 100644
--- a/libs/net/grl-net-mock-private.h
+++ b/libs/net/grl-net-mock-private.h
@@ -31,9 +31,6 @@ G_GNUC_INTERNAL
 gboolean is_mocked (void);
 
 G_GNUC_INTERNAL
-gboolean override_throttling (guint *throttling);
-
-G_GNUC_INTERNAL
 void get_url_mocked (GrlNetWc *self,
                      const char *url,
                      GHashTable *headers,
diff --git a/libs/net/grl-net-mock.c b/libs/net/grl-net-mock.c
index c878903..4f85334 100644
--- a/libs/net/grl-net-mock.c
+++ b/libs/net/grl-net-mock.c
@@ -40,7 +40,6 @@ static GKeyFile *config = NULL;
 static GRegex *ignored_parameters = NULL;
 static char *base_path = NULL;
 static gboolean enable_mocking = FALSE;
-static guint throttle_override = G_MAXUINT;
 
 gboolean
 is_mocked (void)
@@ -48,16 +47,6 @@ is_mocked (void)
   return enable_mocking;
 }
 
-gboolean
-override_throttling (guint *throttling)
-{
-  if (throttle_override == G_MAXUINT)
-    return FALSE;
-
-  *throttling = throttle_override;
-  return TRUE;
-}
-
 void
 get_url_mocked (GrlNetWc *self,
                 const char *url,
@@ -162,39 +151,20 @@ get_content_mocked (GrlNetWc *self,
 
 void init_mock_requester (GrlNetWc *self)
 {
-  char *config_filename = NULL;
+  char *config_filename = g_strdup (g_getenv (GRL_NET_MOCKED_VAR));
   base_path = NULL;
 
   /* Parse environment variable. */
-  {
-    const char *const env = g_getenv (GRL_NET_MOCKED_VAR);
-
-    enable_mocking = env
-            && strcmp(env, "0")
-            && g_ascii_strcasecmp(env, "no")
-            && g_ascii_strcasecmp(env, "off")
-            && g_ascii_strcasecmp(env, "false");
-
-    if (!enable_mocking)
-      return;
-
-    char **tokens = g_strsplit (env, ":", -1);
-
-    for (int i = 0; tokens[i]; ++i) {
-      if (1 == sscanf (tokens[i], "throttle=%u", &throttle_override))
-        continue;
-
-      if (g_str_has_prefix (tokens[i], "config=")) {
-        g_free (config_filename);
-        config_filename = g_strdup (tokens[i] + strlen ("config="));
-        continue;
-      }
-
-      GRL_WARNING ("Unknown token in \"%s\" variable: \"%s\"",
-                   GRL_NET_MOCKED_VAR, tokens[i]);
-    }
-
-    g_strfreev (tokens);
+  enable_mocking = config_filename
+          && strcmp (config_filename, "0")
+          && g_ascii_strcasecmp (config_filename, "no")
+          && g_ascii_strcasecmp (config_filename, "off")
+          && g_ascii_strcasecmp (config_filename, "false");
+
+  if (!enable_mocking) {
+    g_free (config_filename);
+    config_filename = NULL;
+    return;
   }
 
   /* Read configuration file. */
diff --git a/libs/net/grl-net-wc.c b/libs/net/grl-net-wc.c
index dc41678..6920ecd 100644
--- a/libs/net/grl-net-wc.c
+++ b/libs/net/grl-net-wc.c
@@ -192,8 +192,6 @@ grl_net_wc_init (GrlNetWc *wc)
   set_thread_context (wc);
   init_requester (wc);
   init_mock_requester (wc);
-
-  override_throttling (&wc->priv->throttling);
 }
 
 static void
@@ -341,7 +339,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_mocked()) {
     id = g_idle_add_full (G_PRIORITY_HIGH_IDLE,
                           get_url_cb, c, request_clos_destroy);
   } else {
@@ -585,9 +584,6 @@ grl_net_wc_set_throttling (GrlNetWc *self,
 {
   g_return_if_fail (GRL_IS_NET_WC (self));
 
-  if (override_throttling (&throttling))
-    GRL_WARNING ("Overriding throttle setting for mocking");
-
   if (throttling > 0) {
     /* max conns per host = 1 */
     g_object_set (self->priv->session,



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