Skip to content

Commit 0a05d36

Browse files
committed
fix search tests to sleep before Search() call to allow data to be found
1 parent 63558af commit 0a05d36

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

tests/testthat/test-search.r

+33-32
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ test_that("basic search works", {
1212
})
1313

1414
test_that("search for document type works", {
15-
1615
b <- Search(index="shakespeare", type="line")
1716
expect_match(vapply(b$hits$hits, "[[", "", "_type"), "line")
1817
})
@@ -44,42 +43,43 @@ test_that("getting json data back from search works", {
4443
expect_is(jsonlite::fromJSON(f), "list")
4544
})
4645

47-
test_that("Search works with special characters", {
48-
if (index_exists("a+b")) {
49-
invisible(index_delete("a+b"))
50-
}
46+
test_that("Search works with special characters - +", {
47+
invisible(tryCatch(index_delete("a+b"), error = function(e) e))
5148
invisible(index_create("a+b"))
5249
invisible(docs_create(index = "a+b", type = "wiz", id=1, body=list(a="ddd", b="eee")))
5350

54-
vv <- Search(index = "a+b")
55-
56-
expect_is(vv, "list")
57-
expect_equal(length(vv$hits$hits), 1)
58-
expect_equal(vapply(vv$hits$hits, "[[", "", "_index"), 'a+b')
51+
Sys.sleep(1)
52+
aplusb <- Search(index = "a+b")
5953

60-
if (index_exists("a^z")) {
61-
invisible(index_delete("a^z"))
62-
}
63-
index_create("a^z")
54+
expect_is(aplusb, "list")
55+
expect_equal(length(aplusb$hits$hits), 1)
56+
expect_equal(vapply(aplusb$hits$hits, "[[", "", "_index"), 'a+b')
57+
})
58+
59+
test_that("Search works with special characters - ^", {
60+
invisible(tryCatch(index_delete("a^z"), error = function(e) e))
61+
invisible(index_create("a^z"))
6462
invisible(docs_create(index = "a^z", type = "bang", id=1, body=list(a="fff", b="ggg")))
6563

66-
vv <- Search(index = "a^z")
64+
Sys.sleep(1)
65+
ahatz <- Search(index = "a^z")
6766

68-
expect_is(vv, "list")
69-
expect_equal(length(vv$hits$hits), 1)
70-
expect_equal(vapply(vv$hits$hits, "[[", "", "_index"), 'a^z')
67+
expect_is(ahatz, "list")
68+
expect_equal(length(ahatz$hits$hits), 1)
69+
expect_equal(vapply(ahatz$hits$hits, "[[", "", "_index"), 'a^z')
70+
})
7171

72-
if (index_exists("a$z")) {
73-
invisible(index_delete("a$z"))
74-
}
75-
index_create("a$z")
72+
test_that("Search works with special characters - $", {
73+
invisible(tryCatch(index_delete("a$z"), error = function(e) e))
74+
invisible(index_create("a$z"))
7675
invisible(docs_create(index = "a$z", type = "bang", id=1, body=list(a="fff", b="ggg")))
7776

78-
vv <- Search(index = "a$z")
77+
Sys.sleep(1)
78+
adollarz <- Search(index = "a$z")
7979

80-
expect_is(vv, "list")
81-
expect_equal(length(vv$hits$hits), 1)
82-
expect_equal(vapply(vv$hits$hits, "[[", "", "_index"), 'a$z')
80+
expect_is(adollarz, "list")
81+
expect_equal(length(adollarz$hits$hits), 1)
82+
expect_equal(vapply(adollarz$hits$hits, "[[", "", "_index"), 'a$z')
8383
})
8484

8585
test_that("Search works with wild card", {
@@ -88,19 +88,20 @@ test_that("Search works with wild card", {
8888
}
8989
invisible(index_create("voobardang1"))
9090
invisible(docs_create(index = "voobardang1", type = "wiz", id=1, body=list(a="ddd", b="eee")))
91-
91+
9292
if (index_exists("voobardang2")) {
9393
invisible(index_delete("voobardang2"))
9494
}
9595
index_create("voobardang2")
9696
invisible(docs_create(index = "voobardang2", type = "bang", id=1, body=list(a="fff", b="ggg")))
9797

98-
vv <- Search(index = "voobardang*")
98+
Sys.sleep(1)
99+
aster <- Search(index = "voobardang*")
99100

100-
expect_is(vv, "list")
101-
expect_equal(length(vv$hits$hits), 2)
102-
expect_equal(vapply(vv$hits$hits, "[[", "", "_index"), c('voobardang1', 'voobardang2'))
103-
expect_equal(vapply(vv$hits$hits, "[[", "", "_id"), c('1', '1'))
101+
expect_is(aster, "list")
102+
expect_equal(length(aster$hits$hits), 2)
103+
expect_equal(vapply(aster$hits$hits, "[[", "", "_index"), c('voobardang1', 'voobardang2'))
104+
expect_equal(vapply(aster$hits$hits, "[[", "", "_id"), c('1', '1'))
104105
})
105106

106107
test_that("Search fails as expected", {

0 commit comments

Comments
 (0)