/*
This file is part of GNUnet.
- Copyright (C) 2013 GNUnet e.V.
+ Copyright (C) 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
Boston, MA 02110-1301, USA.
*/
/**
- * @file namestore/test_namestore_api_monitoring.c
+ * @file namestore/test_namestore_api_monitoring_existing.c
* @brief testcase for zone monitoring functionality: add records first, then monitor
*/
#include "platform.h"
#include "namestore.h"
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
static const struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
+/**
+ * Re-establish the connection to the service.
+ *
+ * @param cls handle to use to re-connect.
+ */
+static void
+endbadly (void *cls)
+{
+ endbadly_task = NULL;
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
+}
+
+
static void
-do_shutdown ()
+end (void *cls)
{
if (NULL != zm)
{
GNUNET_NAMESTORE_zone_monitor_stop (zm);
zm = NULL;
}
-
if (NULL != ns_ops[0])
{
GNUNET_NAMESTORE_cancel(ns_ops[0]);
GNUNET_NAMESTORE_cancel(ns_ops[2]);
ns_ops[2] = NULL;
}
-
+ if (NULL != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = NULL;
+ }
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
}
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
-static void
-endbadly (void *cls)
-{
- do_shutdown ();
- res = 1;
-}
-
-
-static void
-end (void *cls)
-{
- do_shutdown ();
- res = 0;
-}
-
-
static void
zone_proc (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Monitoring returned wrong zone key\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
1);
if (2 == ++returned_records)
{
- if (endbadly_task != NULL)
+ GNUNET_SCHEDULER_shutdown ();
+ if (GNUNET_YES == fail)
{
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = NULL;
+ GNUNET_break (0);
+ res = 1;
}
- if (GNUNET_YES == fail)
- GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
else
- GNUNET_SCHEDULER_add_now (&end,
- NULL);
+ {
+ res = 0;
+ }
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to created records\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
if (3 == c)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create zone monitor\n");
GNUNET_break (0);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
GNUNET_assert (privkey != NULL);
cfg = mycfg;
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
/**
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+
return res;
}