Skip to content

Commit

Permalink
#341 don't resume HIDDEN or unknown objects
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Aug 8, 2018
1 parent 77bcf3a commit dd9edab
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vstore/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ int16_t corto_mount_resume(
} while (true);
}

if (r) {
if (r && !(r->flags & CORTO_RESULT_HIDDEN) && strcmp(r->type, "unknown")) {
corto_object out = o;
int16_t resume_failed = corto_mount_resumeResult(
this, parent, id, r, &out);
Expand Down
2 changes: 2 additions & 0 deletions test/vstore/model.corto
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ observer
tc_resumeWithAutoFilter()
tc_declareAndResume()
tc_lookupAndResumeUnknown()
tc_defineUnknown()
tc_defineHidden()

method
setup()
Expand Down
12 changes: 11 additions & 1 deletion test/vstore/src/HiddenParentMount.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int16_t test_HiddenParentMount_construct(
"foo",
NULL,
".",
"void",
"int32",
0,
CORTO_RESULT_HIDDEN
);
Expand All @@ -28,6 +28,16 @@ int16_t test_HiddenParentMount_construct(
CORTO_RESULT_LEAF
);

corto_record__assign(
corto_recordList__append_alloc(this->items),
"helloworld",
NULL,
".",
"unknown",
0,
CORTO_RESULT_LEAF
);

return corto_super_construct(this);
}

Expand Down
74 changes: 74 additions & 0 deletions test/vstore/src/ResumeSink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,3 +2017,77 @@ void test_ResumeSink_tc_lookupAndResumeUnknown(
test_assert(corto_delete(o) == 0);
test_assert(corto_delete(m) == 0);
}

void test_ResumeSink_tc_defineHidden(
test_ResumeSink this)
{
/* Create mount with a hidden object 'foo' */
corto_mount m = corto_subscribe("//")
.from("/data")
.mount(test_HiddenParentMount_o, "{ownership: LOCAL_SOURCE}");
test_assert(m != NULL);

corto_object o = corto(CORTO_DECLARE|CORTO_RECURSIVE_DECLARE|CORTO_RESUME, {
.parent = data_o, .id = "foo", .type = corto_int32_o});

test_assert(o != NULL);
test_assertstr(corto_idof(o), "foo");
test_assertref(corto_typeof(o), corto_int32_o);

/* Even though mount provides object, object should not be resumed because
* the object is HIDDEN */
test_assert(!corto_check_state(o, CORTO_VALID));
test_assert(!corto_isresumed(o));

test_assert(corto_delete(o) == 0);
test_assert(corto_delete(m) == 0);
}

static int defineUnknownCount = 0;

void defineUnknownCallback(corto_subscriber_event *e) {
if (e->event == CORTO_DEFINE) {
defineUnknownCount ++;
}
}

void test_ResumeSink_tc_defineUnknown(
test_ResumeSink this)
{
/* Create mount with a unknown object 'helloworld' */
corto_mount m = corto_subscribe("//")
.from("/data")
.mount(test_HiddenParentMount_o, "{ownership: LOCAL_SOURCE}");
test_assert(m != NULL);

/* Create subscriber that monitors DEFINE events */
corto_subscriber s = corto_subscribe("helloworld")
.from("data")
.callback(defineUnknownCallback);

test_assertint(defineUnknownCount, 0);

corto_object o = corto(CORTO_DECLARE|CORTO_RECURSIVE_DECLARE|CORTO_RESUME, {
.parent = data_o, .id = "helloworld", .type = corto_int32_o});

test_assert(o != NULL);
test_assertstr(corto_idof(o), "helloworld");
test_assertref(corto_typeof(o), corto_int32_o);

/* Even though mount provides object, object should not be resumed because
* the object is unknown */
test_assert(!corto_check_state(o, CORTO_VALID));
test_assert(!corto_isresumed(o));
test_assertint(defineUnknownCount, 0);

/* Create object the normal way */
corto_object p = corto_create(data_o, "helloworld", corto_int32_o);
test_assert(o == p);
test_assert(corto_check_state(p, CORTO_VALID));
test_assertint(defineUnknownCount, 1);

test_assert(corto_release(p) == 1);
test_assert(corto_delete(o) == 0);
test_assert(corto_delete(m) == 0);
test_assert(corto_delete(s) == 0);
}
7 changes: 7 additions & 0 deletions test/vstore/src/SelectMount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,13 @@ void test_SelectMount_tc_selectRecursiveFromMountPointParent(
test_assertstr(r->parent, "foo");
test_assertstr(r->type, "void");

test_assert(corto_iter_hasNext(&it) != 0);
r = corto_iter_next(&it);
test_assert(r != NULL);
test_assertstr(r->id, "helloworld");
test_assertstr(r->parent, ".");
test_assertstr(r->type, "unknown");

test_assert(corto_iter_hasNext(&it) == 0);
test_assertint(m->on_query_count, 2);

Expand Down

0 comments on commit dd9edab

Please sign in to comment.