From 043f85210a06168e36f103950897e00918504f6f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 3 Oct 2016 10:46:11 +0200 Subject: tui: "backpressure": Drop messages to avoid flooding. Closes #1234 multiqueue: - Implement multiqueue_size() - Rename MultiQueueItem.parent to MultiQueueItem.parent_item, to avoid confusion with MultiQueue.parent. --- test/unit/multiqueue_spec.lua | 144 ++++++++++++++++++++++++++++++++++++++++++ test/unit/queue_spec.lua | 123 ------------------------------------ 2 files changed, 144 insertions(+), 123 deletions(-) create mode 100644 test/unit/multiqueue_spec.lua delete mode 100644 test/unit/queue_spec.lua (limited to 'test/unit') diff --git a/test/unit/multiqueue_spec.lua b/test/unit/multiqueue_spec.lua new file mode 100644 index 0000000000..c7f8dd8328 --- /dev/null +++ b/test/unit/multiqueue_spec.lua @@ -0,0 +1,144 @@ +local helpers = require("test.unit.helpers") + +local ffi = helpers.ffi +local eq = helpers.eq + +local multiqueue = helpers.cimport("./test/unit/fixtures/multiqueue.h") + +describe("multiqueue (multi-level event-queue)", function() + local parent, child1, child2, child3 + + local function put(q, str) + multiqueue.ut_multiqueue_put(q, str) + end + + local function get(q) + return ffi.string(multiqueue.ut_multiqueue_get(q)) + end + + local function free(q) + multiqueue.multiqueue_free(q) + end + + before_each(function() + parent = multiqueue.multiqueue_new_parent(ffi.NULL, ffi.NULL) + child1 = multiqueue.multiqueue_new_child(parent) + child2 = multiqueue.multiqueue_new_child(parent) + child3 = multiqueue.multiqueue_new_child(parent) + put(child1, 'c1i1') + put(child1, 'c1i2') + put(child2, 'c2i1') + put(child1, 'c1i3') + put(child2, 'c2i2') + put(child2, 'c2i3') + put(child2, 'c2i4') + put(child3, 'c3i1') + put(child3, 'c3i2') + end) + + it('keeps count of added events', function() + eq(3, multiqueue.multiqueue_size(child1)) + eq(4, multiqueue.multiqueue_size(child2)) + eq(2, multiqueue.multiqueue_size(child3)) + end) + + it('keeps count of removed events', function() + multiqueue.multiqueue_get(child1) + eq(2, multiqueue.multiqueue_size(child1)) + multiqueue.multiqueue_get(child1) + eq(1, multiqueue.multiqueue_size(child1)) + multiqueue.multiqueue_get(child1) + eq(0, multiqueue.multiqueue_size(child1)) + put(child1, 'c2ixx') + eq(1, multiqueue.multiqueue_size(child1)) + multiqueue.multiqueue_get(child1) + eq(0, multiqueue.multiqueue_size(child1)) + multiqueue.multiqueue_get(child1) + eq(0, multiqueue.multiqueue_size(child1)) + end) + + it('removing from parent removes from child', function() + eq('c1i1', get(parent)) + eq('c1i2', get(parent)) + eq('c2i1', get(parent)) + eq('c1i3', get(parent)) + eq('c2i2', get(parent)) + eq('c2i3', get(parent)) + eq('c2i4', get(parent)) + end) + + it('removing from child removes from parent', function() + eq('c2i1', get(child2)) + eq('c2i2', get(child2)) + eq('c1i1', get(child1)) + eq('c1i2', get(parent)) + eq('c1i3', get(parent)) + eq('c2i3', get(parent)) + eq('c2i4', get(parent)) + end) + + it('removing from child at the beginning of parent', function() + eq('c1i1', get(child1)) + eq('c1i2', get(child1)) + eq('c2i1', get(parent)) + end) + + it('removing from parent after get from parent and put to child', function() + eq('c1i1', get(parent)) + eq('c1i2', get(parent)) + eq('c2i1', get(parent)) + eq('c1i3', get(parent)) + eq('c2i2', get(parent)) + eq('c2i3', get(parent)) + eq('c2i4', get(parent)) + eq('c3i1', get(parent)) + put(child1, 'c1i11') + put(child1, 'c1i22') + eq('c3i2', get(parent)) + eq('c1i11', get(parent)) + eq('c1i22', get(parent)) + end) + + it('removing from parent after get and put to child', function() + eq('c1i1', get(child1)) + eq('c1i2', get(child1)) + eq('c2i1', get(child2)) + eq('c1i3', get(child1)) + eq('c2i2', get(child2)) + eq('c2i3', get(child2)) + eq('c2i4', get(child2)) + eq('c3i1', get(child3)) + eq('c3i2', get(parent)) + put(child1, 'c1i11') + put(child2, 'c2i11') + put(child1, 'c1i12') + eq('c2i11', get(child2)) + eq('c1i11', get(parent)) + eq('c1i12', get(parent)) + end) + + it('put after removing from child at the end of parent', function() + eq('c3i1', get(child3)) + eq('c3i2', get(child3)) + put(child1, 'c1i11') + put(child2, 'c2i11') + eq('c1i1', get(parent)) + eq('c1i2', get(parent)) + eq('c2i1', get(parent)) + eq('c1i3', get(parent)) + eq('c2i2', get(parent)) + eq('c2i3', get(parent)) + eq('c2i4', get(parent)) + eq('c1i11', get(parent)) + eq('c2i11', get(parent)) + end) + + it('removes from parent queue when child is freed', function() + free(child2) + eq('c1i1', get(parent)) + eq('c1i2', get(parent)) + eq('c1i3', get(parent)) + eq('c3i1', get(child3)) + eq('c3i2', get(child3)) + end) +end) diff --git a/test/unit/queue_spec.lua b/test/unit/queue_spec.lua deleted file mode 100644 index d802367835..0000000000 --- a/test/unit/queue_spec.lua +++ /dev/null @@ -1,123 +0,0 @@ -local helpers = require("test.unit.helpers") - -local ffi = helpers.ffi -local eq = helpers.eq - -local multiqueue = helpers.cimport("./test/unit/fixtures/multiqueue.h") - -describe("multiqueue (multi-level event-queue)", function() - local parent, child1, child2, child3 - - local function put(q, str) - multiqueue.ut_multiqueue_put(q, str) - end - - local function get(q) - return ffi.string(multiqueue.ut_multiqueue_get(q)) - end - - local function free(q) - multiqueue.multiqueue_free(q) - end - - before_each(function() - parent = multiqueue.multiqueue_new_parent(ffi.NULL, ffi.NULL) - child1 = multiqueue.multiqueue_new_child(parent) - child2 = multiqueue.multiqueue_new_child(parent) - child3 = multiqueue.multiqueue_new_child(parent) - put(child1, 'c1i1') - put(child1, 'c1i2') - put(child2, 'c2i1') - put(child1, 'c1i3') - put(child2, 'c2i2') - put(child2, 'c2i3') - put(child2, 'c2i4') - put(child3, 'c3i1') - put(child3, 'c3i2') - end) - - it('removing from parent removes from child', function() - eq('c1i1', get(parent)) - eq('c1i2', get(parent)) - eq('c2i1', get(parent)) - eq('c1i3', get(parent)) - eq('c2i2', get(parent)) - eq('c2i3', get(parent)) - eq('c2i4', get(parent)) - end) - - it('removing from child removes from parent', function() - eq('c2i1', get(child2)) - eq('c2i2', get(child2)) - eq('c1i1', get(child1)) - eq('c1i2', get(parent)) - eq('c1i3', get(parent)) - eq('c2i3', get(parent)) - eq('c2i4', get(parent)) - end) - - it('removing from child at the beginning of parent', function() - eq('c1i1', get(child1)) - eq('c1i2', get(child1)) - eq('c2i1', get(parent)) - end) - - it('removing from parent after get from parent and put to child', function() - eq('c1i1', get(parent)) - eq('c1i2', get(parent)) - eq('c2i1', get(parent)) - eq('c1i3', get(parent)) - eq('c2i2', get(parent)) - eq('c2i3', get(parent)) - eq('c2i4', get(parent)) - eq('c3i1', get(parent)) - put(child1, 'c1i11') - put(child1, 'c1i22') - eq('c3i2', get(parent)) - eq('c1i11', get(parent)) - eq('c1i22', get(parent)) - end) - - it('removing from parent after get and put to child', function() - eq('c1i1', get(child1)) - eq('c1i2', get(child1)) - eq('c2i1', get(child2)) - eq('c1i3', get(child1)) - eq('c2i2', get(child2)) - eq('c2i3', get(child2)) - eq('c2i4', get(child2)) - eq('c3i1', get(child3)) - eq('c3i2', get(parent)) - put(child1, 'c1i11') - put(child2, 'c2i11') - put(child1, 'c1i12') - eq('c2i11', get(child2)) - eq('c1i11', get(parent)) - eq('c1i12', get(parent)) - end) - - it('put after removing from child at the end of parent', function() - eq('c3i1', get(child3)) - eq('c3i2', get(child3)) - put(child1, 'c1i11') - put(child2, 'c2i11') - eq('c1i1', get(parent)) - eq('c1i2', get(parent)) - eq('c2i1', get(parent)) - eq('c1i3', get(parent)) - eq('c2i2', get(parent)) - eq('c2i3', get(parent)) - eq('c2i4', get(parent)) - eq('c1i11', get(parent)) - eq('c2i11', get(parent)) - end) - - it('removes from parent queue when child is freed', function() - free(child2) - eq('c1i1', get(parent)) - eq('c1i2', get(parent)) - eq('c1i3', get(parent)) - eq('c3i1', get(child3)) - eq('c3i2', get(child3)) - end) -end) -- cgit