Skip to content

Commit

Permalink
Changed hostname in integration tests to deal with weirdness in resol…
Browse files Browse the repository at this point in the history
…ving localhost on Travis
  • Loading branch information
jameslamb committed May 31, 2018
1 parent 6096ae8 commit f2d8cf0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
8 changes: 7 additions & 1 deletion R/elasticsearch_eda_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,14 @@ get_fields <- function(es_host
#' @importFrom data.table data.table
#' @importFrom utils read.table
.process_alias <- function(alias_string) {

# process the string provided by the /_cat/aliases API into a data.frame and then a data.table
aliasDT <- data.table::data.table(utils::read.table(text = alias_string, stringsAsFactors = FALSE))
aliasDT <- data.table::data.table(
utils::read.table(
text = alias_string
, stringsAsFactors = FALSE
)
)

# return only the first two columns
return(aliasDT[, .(alias = V1, index = V2)])
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '3'
services:
es_6:
image: "docker.elastic.co/elasticsearch/elasticsearch:6.2.0"
image: "docker.elastic.co/elasticsearch/elasticsearch:5.5.0"
environment:
- "discovery.type=single-node"
#- "discovery.type=single-node"
- "xpack.security.enabled=false"
ports:
- "9200:9200"
2 changes: 1 addition & 1 deletion setup_es.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ curl --silent \
curl -X POST "http://${ES_HOST}:9200/_refresh"

# Check that we got something
curl -X GET "http://${ES_HOST}/shakespeare/_search?size=1"
curl -X GET "http://${ES_HOST}:9200/shakespeare/_search?size=1"
36 changes: 18 additions & 18 deletions tests/testthat/test-integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ futile.logger::flog.threshold(0)
testthat::skip_on_cran()

outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 48
, size = 48
, max_hits = 100
, size = 100
)

expect_true(data.table::is.data.table(outDT))
Expand All @@ -36,35 +36,35 @@ futile.logger::flog.threshold(0)
testthat::skip_on_cran()

outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 50
, max_hits = 30
, size = 2
)
expect_true(data.table::is.data.table(outDT))
expect_true(nrow(outDT) == 48)
expect_true(nrow(outDT) == 30)
})

test_that("es_search works in single-threaded mode", {
testthat::skip_on_cran()

outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 50
, max_hits = 30
, size = 2
, n_cores = 1
)
expect_true(data.table::is.data.table(outDT))
expect_true(nrow(outDT) == 48)
expect_true(nrow(outDT) == 30)
})

test_that("es_search rejects scrolls longer than 1 hour", {
testthat::skip_on_cran()

expect_error({
outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 100
, size = 100
Expand All @@ -79,7 +79,7 @@ futile.logger::flog.threshold(0)

expect_warning({
outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 9999
)
Expand All @@ -93,7 +93,7 @@ futile.logger::flog.threshold(0)

expect_warning({
outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 12
, size = 7
Expand All @@ -110,7 +110,7 @@ futile.logger::flog.threshold(0)
# and I want to avoid exposing our tests to changes in the query DSL
expect_warning({
outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "empty_index"
)
}, regexp = "Query is syntactically valid but 0 documents were matched")
Expand All @@ -122,14 +122,14 @@ futile.logger::flog.threshold(0)
testthat::skip_on_cran()

outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 100
, query = '{"aggs": {"thing": {"terms": {"field": "speaker", "size": 12}}}}'
)

expect_true(data.table::is.data.table(outDT))
expect_true(nrow(outDT) == 3)
expect_true(nrow(outDT) == 12)
expect_named(
outDT
, c("thing", "doc_count")
Expand All @@ -145,7 +145,7 @@ futile.logger::flog.threshold(0)
testthat::skip_on_cran()

outDT <- es_search(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 100
, query = '{"aggs": {"name_i_picked": {"terms": {"field": "speaker", "size": 12}}}}'
Expand All @@ -161,7 +161,7 @@ futile.logger::flog.threshold(0)

# ther stuff we might as well test
expect_true(data.table::is.data.table(outDT))
expect_true(nrow(outDT) == 3)
expect_true(nrow(outDT) == 12)
expect_true(is.numeric(outDT[, doc_count]))
expect_true(is.character(outDT[, name_i_picked]))
expect_true(all(outDT[, doc_count > 0]))
Expand All @@ -173,7 +173,7 @@ futile.logger::flog.threshold(0)
testthat::skip_on_cran()

fieldDT <- get_fields(
es_host = "http://localhost:9200"
es_host = "http://127.0.0.1:9200"
, es_indices = "_all"
)
expect_true(data.table::is.data.table(fieldDT))
Expand Down

0 comments on commit f2d8cf0

Please sign in to comment.