From 2b18ffcf1c5b4cddeb53d642d3ee1e8db86068cf Mon Sep 17 00:00:00 2001 From: Dhaval Kapil Date: Sun, 3 Jul 2016 21:19:11 +0530 Subject: [PATCH] Added Basic framework for stress testing --- .travis.yml | 1 + tests/run-stress-test.lua | 17 +++++++++++++++++ tests/run-stress-test.sh | 13 +++++++++++++ tests/stress/.travis.yml | 39 +++++++++++++++++++++++++++++++++++++++ tests/stress/test.lua | 20 ++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 tests/run-stress-test.lua create mode 100755 tests/run-stress-test.sh create mode 100644 tests/stress/.travis.yml create mode 100644 tests/stress/test.lua diff --git a/.travis.yml b/.travis.yml index 34ea969..4796215 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ after_success: - mv luacov.stats.out ../ - cd ../ - luacov-coveralls -c tests/.luacov + - tests/run-stress-test.sh notifications: email: diff --git a/tests/run-stress-test.lua b/tests/run-stress-test.lua new file mode 100644 index 0000000..8238b9b --- /dev/null +++ b/tests/run-stress-test.lua @@ -0,0 +1,17 @@ +lunit = require "lunit" + +package.path = package.path .. ";../src/?.lua" + +-- Requiring test files +require "stress.test" + +local _, emsg = xpcall(function() + lunit.main(arg) +end, debug.traceback) +if emsg then + print(emsg) + os.exit(1) +end +if lunit.stats.failed > 0 or lunit.stats.errors > 0 then + os.exit(1) +end diff --git a/tests/run-stress-test.sh b/tests/run-stress-test.sh new file mode 100755 index 0000000..4d4baf2 --- /dev/null +++ b/tests/run-stress-test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ -n "$GITHUB_API_KEY" ]; then + git ls-remote --exit-code origin stress-test + if ! test $? = 0; then + git branch -D stress-test + git checkout -b stress-test + cp tests/stress/.travis.yml .travis.yml + git add .travis.yml + git -c user.name='travis' -c user.email='travis' commit -m "Updated travis.yml for stress tests" + git push -f -q https://DhavalKapil:$GITHUB_API_KEY@github.com/DhavalKapil/elasticsearch-lua stress-test + fi +fi diff --git a/tests/stress/.travis.yml b/tests/stress/.travis.yml new file mode 100644 index 0000000..58be902 --- /dev/null +++ b/tests/stress/.travis.yml @@ -0,0 +1,39 @@ +language: c + +sudo: required + +env: + global: + - LUAROCKS=2.2.2 + matrix: + - LUA=lua5.1 + - LUA=lua5.2 + - LUA=lua5.3 + - LUA=luajit # latest stable version (2.0.4) + - LUA=luajit2.0 # current head of 2.0 branch + # - LUA=luajit2.1 # current head of 2.1 branch + +before_install: + - sudo apt-get update && sudo apt-get install wget -y + - .travis/install_es.sh + - source .travis/setenv_lua.sh + - luarocks install lunitx + +install: + - luarocks make elasticsearch-scm-0.rockspec + +before_script: + - echo 'elasticsearch version ' && curl http://localhost:9200/ + +script: + - cd tests + - ./dataset/download-dataset.sh + - lua run-test.lua + +after_script: + - git push https://DhavalKapil:$GITHUB_API_KEY@github.com/DhavalKapil/elasticsearch-lua --delete stress-test + +notifications: + email: + on_success: change + on_failure: always \ No newline at end of file diff --git a/tests/stress/test.lua b/tests/stress/test.lua new file mode 100644 index 0000000..c95248d --- /dev/null +++ b/tests/stress/test.lua @@ -0,0 +1,20 @@ +local elasticsearch = require "elasticsearch" +local dataset = require "dataset.dataset" + +local client = elasticsearch.client() + +-- Setting up environment +local _ENV = lunit.TEST_CASE "tests.stress.test" + +function test() + local res, status = client:index{ + index = "my_index", + type = "my_type", + id = "my_id", + body = dataset[1] + } + + assert_not_nil(res) + assert_true(res.created) + assert_true(status == 200 or status == 201) +end