Discussion:
[ABRT PATCH 2/2] testsuite: fixed the upload watcher test (v3) - related #657
Jiri Moskovcak
2013-08-28 11:13:35 UTC
Permalink
Signed-off-by: Jiri Moskovcak <jmoskovc-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
.../runtests/upload-watcher-stress-test/runtest.sh | 25 +++++++++++++---------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/tests/runtests/upload-watcher-stress-test/runtest.sh b/tests/runtests/upload-watcher-stress-test/runtest.sh
index 4122a6c..9839661 100755
--- a/tests/runtests/upload-watcher-stress-test/runtest.sh
+++ b/tests/runtests/upload-watcher-stress-test/runtest.sh
@@ -50,11 +50,13 @@ rlJournalStart
mkdir -p $WATCHED_DIR

# the upload watcher is not installed by default, but we need it for this test
- rlRun "yum install abrt-addon-upload-watch -y"
+ upload_watch_pkg="abrt-addon-upload-watch"
+ rlRun "rpm -q $upload_watch_pkg >/dev/null || yum install $upload_watch_pkg -y"
# Adding $PWD to PATH in order to override abrt-handle-upload
# by a local script
# Use 60 workers and in the worst case 1GiB for cache
- PATH="$PWD:$PATH:/usr/sbin" abrt-upload-watch -w 60 -c 1024 -v $WATCHED_DIR > out.log 2>&1 &
+ ERR_LOG="err.log"
+ PATH="$PWD:$PATH:/usr/sbin" abrt-upload-watch -w 60 -c 1024 -v $WATCHED_DIR > out.log 2>$ERR_LOG &
PID_OF_WATCH=$!
rlPhaseEnd

@@ -90,14 +92,17 @@ rlJournalStart
CYCLE=0
WAS_SAME=0
while : ; do
- # we can't use size of the log, the output is buffered!
- NEW_SIZE=$(ls -l $WATCHED_DIR 2>/dev/null | wc -l)
-
- if [ $((NEW_SIZE - OLD_SIZE)) -eq 0 ]; then
- WAS_SAME=$((WAS_SAME+1))
- fi
- if [ $WAS_SAME -gt 5 ]; then # it has to be 5 times the same
- break
+ kill -s USR1 $PID_OF_WATCH
+ grep "0 archives to process, 0 active workers" $ERR_LOG
+ if [ x"$?" == x"0" ]; then
+ # we can't use size of the log, the output is buffered!
+ NEW_SIZE=$(ls -l $WATCHED_DIR 2>/dev/null | wc -l)
+ if [ $((NEW_SIZE - OLD_SIZE)) -eq 0 ]; then
+ WAS_SAME=$((WAS_SAME+1))
+ fi
+ if [ $WAS_SAME -gt 5 ]; then # it has to be 5 times the same
+ break
+ fi
fi

OLD_SIZE=$NEW_SIZE
--
1.8.3.1
Richard Marko
2013-08-29 09:53:10 UTC
Permalink
Pushed.
---
src/daemon/abrt-upload-watch.c | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/src/daemon/abrt-upload-watch.c b/src/daemon/abrt-upload-watch.c
index 3ed2854..41d2ba6 100644
--- a/src/daemon/abrt-upload-watch.c
+++ b/src/daemon/abrt-upload-watch.c
@@ -29,6 +29,7 @@
#define DEFAULT_CACHE_MIB_SIZE 4
static int g_signal_pipe[2];
+static sig_atomic_t got_sigusr;
struct queue
{
@@ -123,11 +124,29 @@ handle_new_path(struct process *proc, char *name)
}
}
-static void
-decrement_child_count(struct process *proc)
+static gboolean
+print_stats(struct process *proc)
{
- --proc->children;
+ /* there is a race, because we run this function from 2 different places
+ * 1st when a child dies
+ * 2nd as idle source from mainloop
+ * if it happens the stats will be printed twice, which I think
+ * is not a big deal, because it's only for debug and tests
+ */
+ if (got_sigusr == 1)
+ {
+ got_sigusr = 0;
+ /* this is meant only for debugging, so not marking it as translatable */
+ fprintf(stderr, "%i archives to process, %i active workers\n", g_queue_get_length(&proc->queue.q), proc->children);
+ }
+
+ /* don't remove this source from glib */
+ return true;
+}
+static void
+process_next_in_queue(struct process *proc)
+{
char *name = queue_pop(&proc->queue);
if (!name)
{
@@ -140,6 +159,13 @@ decrement_child_count(struct process *proc)
}
static void
+handle_sigusr(int signo)
+{
+ /* just set the flag and process it synchronously */
+ got_sigusr = 1;
+}
+
+static void
handle_signal(int signo)
{
int save_errno = errno;
@@ -185,7 +211,9 @@ handle_signal_pipe_cb(GIOChannel *gio, GIOCondition condition, gpointer user_dat
{
while (safe_waitpid(-1, NULL, WNOHANG) > 0)
{
- decrement_child_count(proc);
+ --proc->children;
+ process_next_in_queue(proc);
+ print_stats(proc);
}
}
}
@@ -338,6 +366,7 @@ main(int argc, char **argv)
close_on_exec_on(g_signal_pipe[1]);
ndelay_on(g_signal_pipe[0]);
ndelay_on(g_signal_pipe[1]);
+ signal(SIGUSR1, handle_sigusr);
signal(SIGTERM, handle_signal);
signal(SIGINT, handle_signal);
signal(SIGCHLD, handle_signal);
@@ -347,6 +376,7 @@ main(int argc, char **argv)
handle_signal_pipe_cb,
&proc);
+ int status_callback_source_id = g_idle_add((GSourceFunc)print_stats, &proc);
VERB2 log("Starting glib main loop");
g_main_loop_run(proc.main_loop);
@@ -354,6 +384,7 @@ main(int argc, char **argv)
VERB2 log("Glib main loop finished");
g_source_remove(channel_signal_source_id);
+ g_source_remove(status_callback_source_id);
GError *error = NULL;
g_io_channel_shutdown(channel_signal, FALSE, &error);
--
Richard Marko
Loading...