From 2f241d43de3cde86d8862e13a2218e50d8389939 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 14:08:32 -0700 Subject: [PATCH 01/19] Rewrite CI. --- .travis.yml | 114 +++++++++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/.travis.yml b/.travis.yml index d54d2cfd..f67b5309 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,82 +6,96 @@ cache: directories: - here -before_cache: - - rm -rf $HOME/.cache/pip/log - env: global: - - NGINX_VERSION=1.9.15 - - JOBS=3 + - RDB_VER="2.3.0~0" + - JOBS="3" + - LUAJIT_LIB=/usr/lib64/libluajit-5.1.so + - LUAJIT_INC=/usr/include/luajit-2.0 matrix: - - | - LUA="lua 5.1" - LUA_PATH="lua51" - LUA_LIB_NAME="liblua51.a" - RDB_VER="http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_2.3.0~0precise_amd64.deb" + # - | + # LUA="lua 5.1" + # LUA_PATH="lua51" # - | # LUA="lua 5.2" # LUA_PATH="lua52" - # LUA_LIB_NAME="liblua52.a" - # RDB_VER="http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_2.3.0~0precise_amd64.deb" # - | # LUA="lua 5.3" # LUA_PATH="lua53" - # LUA_LIB_NAME="liblua53.a" - # RDB_VER="http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_2.3.0~0precise_amd64.deb" - - | - LUA="luajit 2.0" - LUA_PATH="jit20" - LUA_LIB_NAME="libluajit-5.1.a" - RDB_VER="http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_2.3.0~0precise_amd64.deb" + # RDB_VER="2.3.4~0" + # - | + # LUA="luajit 2.0" + # LUA_PATH="jit20" # - | # LUA="luajit 2.1" # LUA_PATH="jit21" - # LUA_LIB_NAME="libluajit-5.1.a" - # RDB_VER="http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_2.3.0~0precise_amd64.deb" + - | + NGINX_VERSION="1.9.15" + # - | + # NGINX_VERSION="1.8.1" before_install: - # - sudo apt-get update - # - sudo apt-get install -qq -y cpanminus - # - sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1) - - pip install hererocks - - hererocks here/$LUA_PATH -r^ --$LUA - # - ln here/$LUA_PATH/lib/$LUA_LIB_NAME here/$LUA_PATH/lib/liblua.a - - source here/$LUA_PATH/bin/activate - # - export LUA_INCLUDE_DIR=$PWD/here/$LUA_PATH/include - # - export LUA_CMODULE_DIR=$PWD/here/$LUA_PATH/lib/lua/ - # - export LUA_MODULE_DIR=$PWD/here/$LUA_PATH/share/lua/ - # - export LUA_BIN_DIR=$PWD/here/$LUA_PATH/bin - # - git clone https://github.com/openresty/lua-cjson.git - # - cd lua-cjson && make -j$JOBS && sudo make install && cd .. - # - git clone https://github.com/openresty/lua-nginx-module.git - # - wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz - # - tar xzf nginx-${NGINX_VERSION}.tar.gz - # - if [ ${LUA:3:6} == "jit" ]; then export LUAJIT_LIB=$PWD/here/$LUA_PATH/lib; export LUAJIT_INC=$PWD/here/$LUA_PATH/include; else export LUA_LIB=$PWD/here/$LUA_PATH/lib; export LUA_INC=$PWD/here/$LUA_PATH/include; fi - # - cd nginx-${NGINX_VERSION}/ - # - ./configure --with-debug --with-cc-opt="-DDEBUG_MALLOC" --add-module=../lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1) - # - make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) - # - export PATH=$PATH:`pwd`/objs - # - cd .. # previous line changes cwd + - NGINX_VERSION ?= "" + # setup nginx testing + - | + if [ ${NGINX_VERSION} != "" ]; then + sudo apt-get update + sudo apt-get install -qq -y cpanminus libluajit-5.1-dev + sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log + sudo cpanm -v --notest Test::Nginx::Socket > build.log 2>&1 || cat build.log + git clone https://github.com/openresty/lua-cjson.git + cd lua-cjson && make -j$JOBS && sudo make install && cd .. + git clone https://github.com/openresty/lua-nginx-module.git + wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz + tar xzf nginx-${NGINX_VERSION}.tar.gz + cd nginx-${NGINX_VERSION}/ + ./configure --with-debug --with-cc-opt="-DDEBUG_MALLOC" --add-module=../lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1) + make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) + export PATH=$PATH:`pwd`/objs + cd .. # previous line changes cwd + fi + # setup busted testing + - | + if [ ${NGINX_VERSION} == "" ]; then + pip install hererocks + hererocks here/$LUA_PATH -r^ --$LUA + source here/$LUA_PATH/bin/activate + fi - luarocks install luacheck - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - - luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec + - | + if [ ${LUA} == "lua 5.3" ] then + luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec + fi install: - luarocks build --only-deps lua-reql-1.0.2-0.rockspec before_script: - - wget $RDB_VER - - ar x *.deb + - wget http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb + - ar x rethinkdb_${RDB_VER}precise_amd64.deb - tar xvzf data.tar.gz - ./usr/bin/rethinkdb --daemon - - luarocks install busted - - luarocks install luacov-coveralls + # install busted testing + - | + if [ ${NGINX_VERSION} == "" ]; then + luarocks install busted + luarocks install luacov-coveralls + fi script: - - busted --exclude-tags="expensive" - # - prove -r t + - | + if [ ${NGINX_VERSION} == "" ]; then + busted --exclude-tags="expensive" + fi + - | + if [ ${NGINX_VERSION} != "" ]; then + prove -r t + fi + +before_cache: + - rm -rf $HOME/.cache/pip/log after_success: - luacov-coveralls From bb4828a9e5bc38d68cc4a8e6e9263d524703ee7a Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 14:17:18 -0700 Subject: [PATCH 02/19] Remove bad syntax. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f67b5309..d796371e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,6 @@ env: # NGINX_VERSION="1.8.1" before_install: - - NGINX_VERSION ?= "" # setup nginx testing - | if [ ${NGINX_VERSION} != "" ]; then From 9abdb10736c800924121f1605aa8adac1a97fb0c Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 17:06:56 -0700 Subject: [PATCH 03/19] Study scripting. --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d796371e..712a43bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ env: before_install: # setup nginx testing - | - if [ ${NGINX_VERSION} != "" ]; then + if [ -n "$NGINX_VERSION" ]; then sudo apt-get update sudo apt-get install -qq -y cpanminus libluajit-5.1-dev sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log @@ -51,11 +51,11 @@ before_install: ./configure --with-debug --with-cc-opt="-DDEBUG_MALLOC" --add-module=../lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1) make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) export PATH=$PATH:`pwd`/objs - cd .. # previous line changes cwd + cd .. fi # setup busted testing - | - if [ ${NGINX_VERSION} == "" ]; then + if [ -z "$NGINX_VERSION" ]; then pip install hererocks hererocks here/$LUA_PATH -r^ --$LUA source here/$LUA_PATH/bin/activate @@ -64,7 +64,7 @@ before_install: - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - | - if [ ${LUA} == "lua 5.3" ] then + if [ "$LUA" = "lua 5.3" ] then luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec fi @@ -78,18 +78,18 @@ before_script: - ./usr/bin/rethinkdb --daemon # install busted testing - | - if [ ${NGINX_VERSION} == "" ]; then + if [ -z "$NGINX_VERSION" ]; then luarocks install busted luarocks install luacov-coveralls fi script: - | - if [ ${NGINX_VERSION} == "" ]; then + if [ -z "$NGINX_VERSION" ]; then busted --exclude-tags="expensive" fi - | - if [ ${NGINX_VERSION} != "" ]; then + if [ -n "$NGINX_VERSION" ]; then prove -r t fi From bf0d81d0e5c0f1f7e9231b42151bc09129a04172 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 17:07:26 -0700 Subject: [PATCH 04/19] Add luarocks to environment. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 712a43bc..66df0f47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_install: - | if [ -n "$NGINX_VERSION" ]; then sudo apt-get update - sudo apt-get install -qq -y cpanminus libluajit-5.1-dev + sudo apt-get install -qq -y cpanminus libluajit-5.1-dev luarocks sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log sudo cpanm -v --notest Test::Nginx::Socket > build.log 2>&1 || cat build.log git clone https://github.com/openresty/lua-cjson.git From 4f9f205e3ece48014ac355dacec506e90132cae2 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 17:31:41 -0700 Subject: [PATCH 05/19] Elevate luarocks privileges. --- .travis.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66df0f47..e20c25b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,7 @@ before_install: make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) export PATH=$PATH:`pwd`/objs cd .. + sudo luarocks install luacheck fi # setup busted testing - | @@ -59,8 +60,8 @@ before_install: pip install hererocks hererocks here/$LUA_PATH -r^ --$LUA source here/$LUA_PATH/bin/activate + luarocks install luacheck fi - - luarocks install luacheck - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - | @@ -69,7 +70,14 @@ before_install: fi install: - - luarocks build --only-deps lua-reql-1.0.2-0.rockspec + - | + if [ -z "$NGINX_VERSION" ]; then + luarocks build --only-deps lua-reql-1.0.2-0.rockspec + fi + - | + if [ -n "$NGINX_VERSION" ]; then + sudo luarocks build --only-deps lua-reql-1.0.2-0.rockspec + fi before_script: - wget http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb From 07fc11261486b83d9f1096aa9e3839401bacf21f Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 19:16:21 -0700 Subject: [PATCH 06/19] Explore testing environment. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e20c25b7..96600710 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,6 +62,7 @@ before_install: source here/$LUA_PATH/bin/activate luarocks install luacheck fi + - ls -al - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - | From 52ac1c91cd92dab0c55981ebfeeea3501cd72196 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 20:50:35 -0700 Subject: [PATCH 07/19] Fix working directory. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 96600710..ad56f9a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,9 @@ before_install: sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log sudo cpanm -v --notest Test::Nginx::Socket > build.log 2>&1 || cat build.log git clone https://github.com/openresty/lua-cjson.git - cd lua-cjson && make -j$JOBS && sudo make install && cd .. + cd lua-cjson + make -j$JOBS && sudo make install + cd .. git clone https://github.com/openresty/lua-nginx-module.git wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz tar xzf nginx-${NGINX_VERSION}.tar.gz From 2b0e55bab6e5aadf8a8779be515f972d87377d47 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 21:32:46 -0700 Subject: [PATCH 08/19] Fix syntax error. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ad56f9a1..6306c2e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,7 +68,7 @@ before_install: - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - | - if [ "$LUA" = "lua 5.3" ] then + if [ "$LUA" = "lua 5.3" ]; then luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec fi From 993c98b13b20f0d948abe695ee67b9c3de576126 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 27 Aug 2016 21:51:54 -0700 Subject: [PATCH 09/19] Add ssl. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6306c2e3..d0d2c709 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_install: - | if [ -n "$NGINX_VERSION" ]; then sudo apt-get update - sudo apt-get install -qq -y cpanminus libluajit-5.1-dev luarocks + sudo apt-get install -qq -y libssl-dev cpanminus libluajit-5.1-dev luarocks sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log sudo cpanm -v --notest Test::Nginx::Socket > build.log 2>&1 || cat build.log git clone https://github.com/openresty/lua-cjson.git @@ -64,7 +64,7 @@ before_install: source here/$LUA_PATH/bin/activate luarocks install luacheck fi - - ls -al + - ls -al $LUAJIT_INC - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - | From 650f5781f4988e45674e09b0c18f4d12f825e92b Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 4 Sep 2016 14:28:47 -0700 Subject: [PATCH 10/19] Reset testing infrastructure. --- .travis.yml | 110 +++++++++++++--------------------------------------- t/connect.t | 37 ------------------ t/query.t | 83 --------------------------------------- 3 files changed, 28 insertions(+), 202 deletions(-) delete mode 100644 t/connect.t delete mode 100644 t/query.t diff --git a/.travis.yml b/.travis.yml index d0d2c709..66e8a236 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: python -sudo: required +sudo: false cache: pip: true @@ -8,101 +8,47 @@ cache: env: global: - - RDB_VER="2.3.0~0" - - JOBS="3" - - LUAJIT_LIB=/usr/lib64/libluajit-5.1.so - - LUAJIT_INC=/usr/include/luajit-2.0 + - RDB_VER="2.3.5~0" matrix: - # - | - # LUA="lua 5.1" - # LUA_PATH="lua51" - # - | - # LUA="lua 5.2" - # LUA_PATH="lua52" - # - | - # LUA="lua 5.3" - # LUA_PATH="lua53" - # RDB_VER="2.3.4~0" - # - | - # LUA="luajit 2.0" - # LUA_PATH="jit20" - # - | - # LUA="luajit 2.1" - # LUA_PATH="jit21" - - | - NGINX_VERSION="1.9.15" - # - | - # NGINX_VERSION="1.8.1" + - | + LUA="lua 5.1" + LUA_PATH="lua51" + - | + LUA="lua 5.2" + LUA_PATH="lua52" + - | + LUA="lua 5.3" + LUA_PATH="lua53" + RDB_VER="2.3.4~0" + - | + LUA="luajit 2.0" + LUA_PATH="jit20" + - | + LUA="luajit 2.1" + LUA_PATH="jit21" before_install: - # setup nginx testing - - | - if [ -n "$NGINX_VERSION" ]; then - sudo apt-get update - sudo apt-get install -qq -y libssl-dev cpanminus libluajit-5.1-dev luarocks - sudo cpanm -v --notest Test::Nginx > build.log 2>&1 || cat build.log - sudo cpanm -v --notest Test::Nginx::Socket > build.log 2>&1 || cat build.log - git clone https://github.com/openresty/lua-cjson.git - cd lua-cjson - make -j$JOBS && sudo make install - cd .. - git clone https://github.com/openresty/lua-nginx-module.git - wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz - tar xzf nginx-${NGINX_VERSION}.tar.gz - cd nginx-${NGINX_VERSION}/ - ./configure --with-debug --with-cc-opt="-DDEBUG_MALLOC" --add-module=../lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1) - make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) - export PATH=$PATH:`pwd`/objs - cd .. - sudo luarocks install luacheck - fi - # setup busted testing - - | - if [ -z "$NGINX_VERSION" ]; then - pip install hererocks - hererocks here/$LUA_PATH -r^ --$LUA - source here/$LUA_PATH/bin/activate - luarocks install luacheck - fi - - ls -al $LUAJIT_INC + - pip install hererocks + - hererocks here/$LUA_PATH -r^ --$LUA + - source here/$LUA_PATH/bin/activate + - luarocks install luacheck - luacheck src # Fix from https://github.com/leafo/lapis/issues/6 - - | - if [ "$LUA" = "lua 5.3" ]; then - luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec - fi + - luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec install: - - | - if [ -z "$NGINX_VERSION" ]; then - luarocks build --only-deps lua-reql-1.0.2-0.rockspec - fi - - | - if [ -n "$NGINX_VERSION" ]; then - sudo luarocks build --only-deps lua-reql-1.0.2-0.rockspec - fi + - luarocks build --only-deps lua-reql-1.0.2-0.rockspec before_script: - - wget http://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb + - wget https://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb - ar x rethinkdb_${RDB_VER}precise_amd64.deb - tar xvzf data.tar.gz - ./usr/bin/rethinkdb --daemon - # install busted testing - - | - if [ -z "$NGINX_VERSION" ]; then - luarocks install busted - luarocks install luacov-coveralls - fi + - luarocks install busted + - luarocks install luacov-coveralls script: - - | - if [ -z "$NGINX_VERSION" ]; then - busted --exclude-tags="expensive" - fi - - | - if [ -n "$NGINX_VERSION" ]; then - prove -r t - fi + - busted --exclude-tags="expensive" before_cache: - rm -rf $HOME/.cache/pip/log diff --git a/t/connect.t b/t/connect.t deleted file mode 100644 index 2cc4009c..00000000 --- a/t/connect.t +++ /dev/null @@ -1,37 +0,0 @@ -use Test::Nginx::Socket::Lua; - -plan tests => repeat_each() * (3 * blocks()); - -our $HttpConfig = <<'_EOC_'; - lua_package_path 'src/?.lua;src/?/?.lua;;'; - error_log logs/error.log debug; -_EOC_ - -no_long_string(); - -run_tests(); - -__DATA__ - -=== Connect ---- http_config eval: $::HttpConfig ---- config - location /t { - content_by_lua " - local r = require 'rethinkdb' - - r.connect(function(err, c) - if err then - error(err.message()) - end - - assert(c, 'Connection failed') - ngx.print('pass') - end) - "; - } ---- request -GET /t ---- response_body: pass ---- no_error_log -[error] diff --git a/t/query.t b/t/query.t deleted file mode 100644 index 8aed2aa8..00000000 --- a/t/query.t +++ /dev/null @@ -1,83 +0,0 @@ -use Test::Nginx::Socket::Lua; - -plan tests => repeat_each() * (3 * blocks()); - -our $HttpConfig = <<'_EOC_'; - lua_package_path 'src/?.lua;src/?/?.lua;;'; - error_log logs/error.log debug; -_EOC_ - -no_long_string(); - -run_tests(); - -__DATA__ - -=== Query ---- http_config eval: $::HttpConfig ---- config - location /t { - content_by_lua " - local r = require 'rethinkdb' - - local reql_db = 'dbtest' - local reql_table = 'test' - local document_name = 'test document' - local document = { - name = document_name - } - - r.connect(function(err, c) - if err then - error(err.message()) - end - - assert(c, 'Connection failed') - - local function setup(callback) - -- init db - r.reql.db_create(reql_db).run(c).to_array() - c.use(reql_db) - r.reql.table_create(reql_table).run(c, function() - -- remove data - r.reql.table(reql_table).delete().run(c, callback) - end) - end - - setup(function() - -- insert doc - r.reql.table(reql_table).insert(document).run(c, function(err, cur) - if err then - error(err.message()) - end - - _, err = cur.to_array() - if err then - error(err.message()) - end - - r.reql.table(reql_table).run(c, function(err, cur) - if err then - error(err.message()) - end - - local arr, err = cur.to_array() - if err then - error(err.message()) - end - - assert(#arr == 1, 'Wrong array length') - assert(arr[1].name == document_name, 'Wrong document name') - - ngx.print('pass') - end) - end) - end) - end) - "; - } ---- request -GET /t ---- response_body: pass ---- no_error_log -[error] From 36ab897bdfda2cd801d80984c0c30ab21b7093d5 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Mon, 5 Sep 2016 18:50:45 -0700 Subject: [PATCH 11/19] Fallback on normal settimeout. --- src/rethinkdb/internal/socket.lua | 14 ++++++++++---- src/rethinkdb/internal/utilities.lua | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rethinkdb/internal/socket.lua b/src/rethinkdb/internal/socket.lua index db2b937b..4f91d995 100644 --- a/src/rethinkdb/internal/socket.lua +++ b/src/rethinkdb/internal/socket.lua @@ -5,6 +5,8 @@ -- @copyright Adam Grandquist 2016 local ssl = require('ssl') +local socket_sink = require('socket').sink +local socket_source = require('socket').source local function socket(r, host, port, ssl_params, timeout) local raw_socket, init_err = r.tcp() @@ -13,9 +15,13 @@ local function socket(r, host, port, ssl_params, timeout) return nil, init_err end - raw_socket:settimeout(timeout) + local status = pcall(raw_socket:settimeout, timeout, 't') and + pcall(raw_socket:settimeout, timeout, 'b') or + pcall(raw_socket:settimeout, timeout) - local status + if not status then + return nil, 'Failed to set timeout' + end status, init_err = raw_socket:connect(host, port) @@ -41,10 +47,10 @@ local function socket(r, host, port, ssl_params, timeout) local socket_inst = {} - socket_inst.sink = r.socket.sink('keep-open', raw_socket) + socket_inst.sink = socket_sink('keep-open', raw_socket) function socket_inst.source(_r, length) - return _r.socket.source('by-length', raw_socket, length) + return socket_source('by-length', raw_socket, length) end function socket_inst.close() diff --git a/src/rethinkdb/internal/utilities.lua b/src/rethinkdb/internal/utilities.lua index 971e2f0e..52a13cfa 100644 --- a/src/rethinkdb/internal/utilities.lua +++ b/src/rethinkdb/internal/utilities.lua @@ -14,8 +14,6 @@ if ngx == nil then --luacheck: globals ngx else json = require('cjson') socket = ngx.socket --luacheck: globals ngx - socket.sink = require('socket').sink - socket.source = require('socket').source end local m = {} From 3deecfb8142d91c820f207c3749fcd42d802cd80 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Mon, 5 Sep 2016 18:55:48 -0700 Subject: [PATCH 12/19] Explicit pass of self. --- src/rethinkdb/internal/socket.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rethinkdb/internal/socket.lua b/src/rethinkdb/internal/socket.lua index 4f91d995..056755a0 100644 --- a/src/rethinkdb/internal/socket.lua +++ b/src/rethinkdb/internal/socket.lua @@ -8,6 +8,10 @@ local ssl = require('ssl') local socket_sink = require('socket').sink local socket_source = require('socket').source +local function settimeout(socket, ...) + return pcall(socket.settimeout, socket, ...) +end + local function socket(r, host, port, ssl_params, timeout) local raw_socket, init_err = r.tcp() @@ -15,9 +19,9 @@ local function socket(r, host, port, ssl_params, timeout) return nil, init_err end - local status = pcall(raw_socket:settimeout, timeout, 't') and - pcall(raw_socket:settimeout, timeout, 'b') or - pcall(raw_socket:settimeout, timeout) + local status = settimeout(raw_socket, timeout, 't') and + settimeout(raw_socket, timeout, 'b') or + settimeout(raw_socket, timeout) if not status then return nil, 'Failed to set timeout' From 1efa80ef3e9b2cfe6672439cc1eae5a6050f81e1 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Tue, 6 Sep 2016 19:26:08 -0700 Subject: [PATCH 13/19] Unwind extra argument. --- spec/internal/socket_spec.lua | 2 +- src/rethinkdb/connection_instance.lua | 2 +- src/rethinkdb/depreciate.lua | 10 +++++----- src/rethinkdb/internal/current_handshake.lua | 2 +- src/rethinkdb/internal/protocol.lua | 4 ++-- src/rethinkdb/internal/socket.lua | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/internal/socket_spec.lua b/spec/internal/socket_spec.lua index 191e03f1..6cb696d8 100644 --- a/spec/internal/socket_spec.lua +++ b/spec/internal/socket_spec.lua @@ -42,7 +42,7 @@ describe('socket', function() 'server?\n\0', } - assert.is_truthy(ltn12.pump.all(client.source(r, string.len(expected)), sink)) + assert.is_truthy(ltn12.pump.all(client.source(string.len(expected)), sink)) local message = table.concat(buffer) diff --git a/src/rethinkdb/connection_instance.lua b/src/rethinkdb/connection_instance.lua index efac4ceb..da44e1be 100644 --- a/src/rethinkdb/connection_instance.lua +++ b/src/rethinkdb/connection_instance.lua @@ -120,7 +120,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti function state.step() -- Buffer data, execute return results if need be while not responses[token] do - local success, err = ltn12.pump.step(protocol_inst.source(conn_inst.r), sink) + local success, err = ltn12.pump.step(protocol_inst.source(), sink) if not success then return reset(err) end diff --git a/src/rethinkdb/depreciate.lua b/src/rethinkdb/depreciate.lua index 3fb34255..54bc7d5b 100644 --- a/src/rethinkdb/depreciate.lua +++ b/src/rethinkdb/depreciate.lua @@ -7,7 +7,7 @@ local int_to_little = require'rethinkdb.internal.int_to_bytes'.little local ltn12 = require('ltn12') -local function proto_V0_x(r, socket_inst, auth_key, magic) +local function proto_V0_x(socket_inst, auth_key, magic) -- Initialize connection with magic number to validate version local data = table.concat{ @@ -27,14 +27,14 @@ local function proto_V0_x(r, socket_inst, auth_key, magic) -- acknowledging the connection while true do if string.len(table.concat(buffer)) > 8 then - success, err = ltn12.pump.all(socket_inst.source(r, 1), sink) + success, err = ltn12.pump.all(socket_inst.source(1), sink) socket_inst.close() if not success then return nil, err end return nil, table.concat(buffer) end - success, err = ltn12.pump.step(socket_inst.source(r, 1), sink) + success, err = ltn12.pump.step(socket_inst.source(1), sink) if not success then return nil, err end @@ -52,14 +52,14 @@ function m.init(r) -- server version 1.16+. Passed to proto_version connection option. Will be -- removed in driver version 2. function r.proto_V0_3(_, socket_inst, auth_key) - return proto_V0_x(r, socket_inst, auth_key, '\62\232\117\95') + return proto_V0_x(socket_inst, auth_key, '\62\232\117\95') end --- Depreciated implementation of RethinkDB handshake version 0.4. Supports -- server version 2.0+. Passed to proto_version connection option. Will be -- removed in driver version 2. function r.proto_V0_4(_, socket_inst, auth_key) - return proto_V0_x(r, socket_inst, auth_key, '\32\45\12\64') + return proto_V0_x(socket_inst, auth_key, '\32\45\12\64') end end diff --git a/src/rethinkdb/internal/current_handshake.lua b/src/rethinkdb/internal/current_handshake.lua index c1b17a08..d1c1ad84 100644 --- a/src/rethinkdb/internal/current_handshake.lua +++ b/src/rethinkdb/internal/current_handshake.lua @@ -90,7 +90,7 @@ local function current_handshake(r, socket_inst, auth_key, user) local function get_message() local i = string.find(buffer, '\0') while not i do - local success, err = ltn12.pump.step(socket_inst.source(r, 1), sink) + local success, err = ltn12.pump.step(socket_inst.source(1), sink) if not success then return nil, err end diff --git a/src/rethinkdb/internal/protocol.lua b/src/rethinkdb/internal/protocol.lua index c00772e3..4483b7fb 100644 --- a/src/rethinkdb/internal/protocol.lua +++ b/src/rethinkdb/internal/protocol.lua @@ -156,8 +156,8 @@ local function protocol(socket_inst) return write_socket(get_token(), SERVER_INFO) end - function protocol_inst.source(r) - return ltn12.source.chain(socket_inst.source(r, ctx.response_length or 12), filter) + function protocol_inst.source() + return ltn12.source.chain(socket_inst.source(ctx.response_length or 12), filter) end return protocol_inst diff --git a/src/rethinkdb/internal/socket.lua b/src/rethinkdb/internal/socket.lua index 056755a0..4733ea5c 100644 --- a/src/rethinkdb/internal/socket.lua +++ b/src/rethinkdb/internal/socket.lua @@ -53,7 +53,7 @@ local function socket(r, host, port, ssl_params, timeout) socket_inst.sink = socket_sink('keep-open', raw_socket) - function socket_inst.source(_r, length) + function socket_inst.source(length) return socket_source('by-length', raw_socket, length) end From 87a331bd5edacda73d06989b24052f320f707447 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 25 Dec 2016 08:02:53 -0800 Subject: [PATCH 14/19] Fix errors squashing callbacks. --- spec/connection_spec.lua | 10 +++ src/rethinkdb/connection_instance.lua | 89 ++++++++++++--------------- src/rethinkdb/cursor.lua | 18 +++--- src/rethinkdb/reql.lua | 4 +- 4 files changed, 63 insertions(+), 58 deletions(-) diff --git a/spec/connection_spec.lua b/spec/connection_spec.lua index a18ca2b0..825ef46d 100644 --- a/spec/connection_spec.lua +++ b/spec/connection_spec.lua @@ -33,6 +33,16 @@ describe('connection', function() assert.is_nil(err.ReQLAuthError) end) + it('bad password', function() + local conn, err = r.connect({password = '0xDEADBEEF'}, function(err, c) + return c, err + end) + assert.is_nil(conn) + assert.is_table(err) + assert.is_table(err.ReQLDriverError) + assert.is_table(err.ReQLAuthError) + end) + it('return conn', function() local conn, err = r.connect() assert.is_nil(err) diff --git a/src/rethinkdb/connection_instance.lua b/src/rethinkdb/connection_instance.lua index da44e1be..558302bb 100644 --- a/src/rethinkdb/connection_instance.lua +++ b/src/rethinkdb/connection_instance.lua @@ -11,7 +11,10 @@ local protocol = require'rethinkdb.internal.protocol' local protect = require'rethinkdb.internal.protect' local socket = require'rethinkdb.internal.socket' -local unpack = _G.unpack or table.unpack +local function with(inline, ...) + inline() + return ... +end local conn_inst_meta_table = {} @@ -22,22 +25,24 @@ function conn_inst_meta_table.__tostring(conn_inst) end local function connection_instance(r, handshake_inst, host, port, ssl_params, timeout) - local db = nil - local outstanding_callbacks = {} - local protocol_inst = nil - local responses = {} + local db, outstanding_callbacks, protocol_inst, responses = nil, {}, nil, {} - local function reset(err) - if protocol_inst then protocol_inst.close() end - protocol_inst = nil + local function reset(err, callback) + local function cb(...) + if type(callback) == 'function' then + return callback(...) + end + return nil, ... + end for _, state in pairs(outstanding_callbacks) do state.open = nil end - outstanding_callbacks = {} + if protocol_inst then protocol_inst.close() end + db, outstanding_callbacks, protocol_inst, responses = nil, {}, nil, {} if type(err) == 'string' then - return nil, errors.ReQLDriverError(r, err) + return cb(errors.ReQLDriverError(r, err)) end - return nil, err + return cb(err) end local conn_inst = setmetatable( @@ -73,7 +78,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti if not chunk then return nil, err end - local token, response = unpack(chunk) + local token, response = chunk[1], chunk[2] if token then local state = outstanding_callbacks[token] if not state then @@ -138,9 +143,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti local function cb(err, cur) if type(callback) == 'function' then if cur then - local res = {callback(err, cur)} - cur.close() - return unpack(res) + return with(cur.close, callback(err, cur)) end return callback(err) end @@ -169,7 +172,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti local token, err = protocol_inst.send_query(conn_inst.r, reql_inst, global_opts) if err then - return cb(err) + return reset(err, cb) end if options.noreply then @@ -201,18 +204,14 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti conn_inst.noreply_wait() end - reset() - - if callback then - return callback() - end + return reset(nil, callback) end function conn_inst.connect(callback) local socket_inst, err = socket(conn_inst.r, conn_inst.host, conn_inst.port, ssl_params, timeout) if not socket_inst then - return reset(err) + return reset(err, callback) end local init_success @@ -222,25 +221,21 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti if not init_success then if type(err) == 'table' then if 10 <= err.error_code and err.error_code <= 20 then - return reset(errors.ReQLAuthError(r, err.error)) + return reset(errors.ReQLAuthError(r, err.error), callback) end - return reset(err.error) + return reset(err.error, callback) end - return reset(err) + return reset(err, callback) end protocol_inst, err = protocol(socket_inst) if not protocol_inst then - return reset(err) + return reset(err, callback) end if callback then - local function with(...) - reset() - return ... - end - return with(callback(nil, conn_inst)) + return with(reset, callback(nil, conn_inst)) end return conn_inst @@ -250,14 +245,14 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti -- processed by the server. Note that this guarantee only applies to queries -- run on the given connection. function conn_inst.noreply_wait(callback) - local function cb(err, success) - if callback then - return callback(err, success) - end + local function cb(err) if err then - return reset(err) + return reset(err, callback) + end + if callback then + return callback(nil, true) end - return success + return true end if not conn_inst.is_open() then return cb(errors.ReQLDriverError(r, 'Connection is closed.')) end @@ -269,10 +264,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti end local _, e = make_cursor(token, {}, {}).to_array() - if e then - return cb(e) - end - return cb(nil, true) + return cb(e) end --- Close and reopen a connection. Accepts the following options. @@ -291,14 +283,14 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti end function conn_inst.server(callback) - local function cb(err, ...) - if callback then - return callback(err, ...) - end + local function cb(err, arr) if err then - return reset(err) + return reset(err, callback) + end + if callback then + return callback(nil, arr) end - return ... + return arr end if not conn_inst.is_open() then return cb(errors.ReQLDriverError(r, 'Connection is closed.')) end @@ -309,7 +301,8 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti return cb(err) end - return cb(make_cursor(token, {}, {}).to_array()) + local arr, e = make_cursor(token, {}, {}).to_array() + return cb(e, arr) end return conn_inst diff --git a/src/rethinkdb/cursor.lua b/src/rethinkdb/cursor.lua index 19a4c78e..8552b3f3 100644 --- a/src/rethinkdb/cursor.lua +++ b/src/rethinkdb/cursor.lua @@ -99,7 +99,7 @@ local function each(state, var) if type(err) == 'table' then return 0, err end - return 0, errors.ReQLDriverError({}, err) -- @todo + return 0, errors.ReQLDriverError({}, err) end end local row = state.it() @@ -161,9 +161,10 @@ local function cursor(r, state, options, reql_inst) end --- Set or clear a callback for asynchronous processing of query results. - -- Calling without arguments clears any previous function set, and retains - -- results for future retrieval. This will only be called if another cursor - -- from the same connection is retrieving rows synchronously. + -- This callback will only be called if another + -- cursor from the same connection is retrieving rows synchronously. Calling + -- without arguments clears any previous function set, and retains results for + -- future retrieval. function cursor_inst.set(callback) state.outstanding_callback = callback if callback then @@ -191,10 +192,11 @@ local function cursor(r, state, options, reql_inst) end --- Supports iteration with a for loop. First variable is an auto incrementing - -- integer starting at 1. This does not correspond with any data on the - -- server. If this is 0 then the row is an error. This error will be returned - -- forever and the caller is responsible for breaking out of the loop. The - -- second variable is a row result from the query or an error. + -- integer starting at 1. This integer does not correspond with any data on + -- the server. If this is 0 then the row is an error. This error will be + -- returned forever and the caller is responsible for breaking out of the + -- loop. The second variable is a row result from the query or an error. + -- Errors returned in a loop do not have valid links to the driver instance. function cursor_inst.each() cursor_inst.set() return each, state, 0 diff --git a/src/rethinkdb/reql.lua b/src/rethinkdb/reql.lua index 7d0e6a0b..1e33affc 100644 --- a/src/rethinkdb/reql.lua +++ b/src/rethinkdb/reql.lua @@ -378,11 +378,11 @@ function m.init(r) function reql_meta_table.__call(reql, val, nesting_depth) nesting_depth = nesting_depth or 20 if nesting_depth <= 0 then - return nil, errors.ReQLDriverError(r, 'Nesting depth limit exceeded') -- @todo + return nil, errors.ReQLDriverError(r, 'Nesting depth limit exceeded') end local continue = continue_reql[type(val)] if not continue then - return nil, errors.ReQLDriverError(r, 'Unknown Lua type ' .. type(val)) -- @todo + return nil, errors.ReQLDriverError(r, 'Unknown Lua type ' .. type(val)) end return continue(r, reql, val, nesting_depth) end From bdf5416df3b42aa312a94eb5e439b5589572f021 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 25 Dec 2016 08:25:42 -0800 Subject: [PATCH 15/19] Improve test to prevent false positive. --- spec/connection_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/connection_spec.lua b/spec/connection_spec.lua index 825ef46d..08f4eb28 100644 --- a/spec/connection_spec.lua +++ b/spec/connection_spec.lua @@ -34,10 +34,10 @@ describe('connection', function() end) it('bad password', function() - local conn, err = r.connect({password = '0xDEADBEEF'}, function(err, c) - return c, err + local err = r.connect({password = '0xDEADBEEF'}, function(err, c) + assert.is_nil(c) + return err end) - assert.is_nil(conn) assert.is_table(err) assert.is_table(err.ReQLDriverError) assert.is_table(err.ReQLAuthError) From 2537280deb968986f8e868e4ef2b6471af2f09f8 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 25 Dec 2016 09:28:45 -0800 Subject: [PATCH 16/19] Push error creation down in the call stack. --- src/rethinkdb/connection_instance.lua | 26 +++------- src/rethinkdb/connector.lua | 26 ++++------ src/rethinkdb/cursor.lua | 17 +++---- src/rethinkdb/depreciate.lua | 20 ++++---- src/rethinkdb/internal/current_handshake.lua | 53 +++++++++++++------- src/rethinkdb/internal/protocol.lua | 28 ++++++----- src/rethinkdb/internal/socket.lua | 22 ++++---- 7 files changed, 97 insertions(+), 95 deletions(-) diff --git a/src/rethinkdb/connection_instance.lua b/src/rethinkdb/connection_instance.lua index 558302bb..b5cd2328 100644 --- a/src/rethinkdb/connection_instance.lua +++ b/src/rethinkdb/connection_instance.lua @@ -28,21 +28,15 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti local db, outstanding_callbacks, protocol_inst, responses = nil, {}, nil, {} local function reset(err, callback) - local function cb(...) - if type(callback) == 'function' then - return callback(...) - end - return nil, ... - end for _, state in pairs(outstanding_callbacks) do state.open = nil end if protocol_inst then protocol_inst.close() end db, outstanding_callbacks, protocol_inst, responses = nil, {}, nil, {} - if type(err) == 'string' then - return cb(errors.ReQLDriverError(r, err)) + if type(callback) == 'function' then + return callback(err) end - return cb(err) + return nil, err end local conn_inst = setmetatable( @@ -62,7 +56,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti end local function add_response(token, response, state) - protocol_inst.continue_query(token) + protocol_inst.continue_query(conn_inst.r, token) local err response, err = protect(conn_inst.r.decode, response) @@ -108,7 +102,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti function state.end_query() if protocol_inst then - return protocol_inst.end_query(token) + return protocol_inst.end_query(conn_inst.r, token) end end @@ -219,12 +213,6 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti init_success, err = handshake_inst(conn_inst.r, socket_inst) if not init_success then - if type(err) == 'table' then - if 10 <= err.error_code and err.error_code <= 20 then - return reset(errors.ReQLAuthError(r, err.error), callback) - end - return reset(err.error, callback) - end return reset(err, callback) end @@ -257,7 +245,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti if not conn_inst.is_open() then return cb(errors.ReQLDriverError(r, 'Connection is closed.')) end -- Construct query - local token, err = protocol_inst.noreply_wait() + local token, err = protocol_inst.noreply_wait(conn_inst.r) if not token then return cb(err) @@ -295,7 +283,7 @@ local function connection_instance(r, handshake_inst, host, port, ssl_params, ti if not conn_inst.is_open() then return cb(errors.ReQLDriverError(r, 'Connection is closed.')) end -- Construct query - local token, err = protocol_inst.server_info() + local token, err = protocol_inst.server_info(conn_inst.r) if not token then return cb(err) diff --git a/src/rethinkdb/connector.lua b/src/rethinkdb/connector.lua index 89739bba..30bf415f 100644 --- a/src/rethinkdb/connector.lua +++ b/src/rethinkdb/connector.lua @@ -39,6 +39,14 @@ function m.init(r) local connector_inst = setmetatable({r = r}, connector_inst_meta_table) function connector_inst.connect(callback) + local connection = connection_instance( + connector_inst.r, + handshake_inst, + host, + port, + ssl_params, + timeout + ) if callback then local function cb(err, conn) if err then @@ -47,24 +55,10 @@ function m.init(r) conn.use(db) return callback(nil, conn) end - return connection_instance( - connector_inst.r, - handshake_inst, - host, - port, - ssl_params, - timeout - ).connect(cb) + return connection.connect(cb) end - local conn, err = connection_instance( - connector_inst.r, - handshake_inst, - host, - port, - ssl_params, - timeout - ).connect() + local conn, err = connection.connect() if err then return nil, err end diff --git a/src/rethinkdb/cursor.lua b/src/rethinkdb/cursor.lua index 8552b3f3..6b0ef08f 100644 --- a/src/rethinkdb/cursor.lua +++ b/src/rethinkdb/cursor.lua @@ -96,10 +96,7 @@ local function each(state, var) end local success, err = state.step() if not success then - if type(err) == 'table' then - return 0, err - end - return 0, errors.ReQLDriverError({}, err) + return 0, err end end local row = state.it() @@ -160,11 +157,10 @@ local function cursor(r, state, options, reql_inst) end end - --- Set or clear a callback for asynchronous processing of query results. - -- This callback will only be called if another - -- cursor from the same connection is retrieving rows synchronously. Calling - -- without arguments clears any previous function set, and retains results for - -- future retrieval. + --- Set or clear a callback for asynchronous processing of query results. This + -- callback will only be called if another cursor from the same connection is + -- retrieving rows synchronously. Calling without arguments clears any + -- previous function set, and retains results for future retrieval. function cursor_inst.set(callback) state.outstanding_callback = callback if callback then @@ -196,7 +192,8 @@ local function cursor(r, state, options, reql_inst) -- the server. If this is 0 then the row is an error. This error will be -- returned forever and the caller is responsible for breaking out of the -- loop. The second variable is a row result from the query or an error. - -- Errors returned in a loop do not have valid links to the driver instance. + -- Errors returned in a loop may be strings if a valid link to the driver + -- instance is not available. function cursor_inst.each() cursor_inst.set() return each, state, 0 diff --git a/src/rethinkdb/depreciate.lua b/src/rethinkdb/depreciate.lua index 54bc7d5b..c3d3872e 100644 --- a/src/rethinkdb/depreciate.lua +++ b/src/rethinkdb/depreciate.lua @@ -4,10 +4,11 @@ -- @license Apache -- @copyright Adam Grandquist 2016 +local errors = require'rethinkdb.errors' local int_to_little = require'rethinkdb.internal.int_to_bytes'.little local ltn12 = require('ltn12') -local function proto_V0_x(socket_inst, auth_key, magic) +local function proto_V0_x(r, socket_inst, auth_key, magic) -- Initialize connection with magic number to validate version local data = table.concat{ @@ -18,7 +19,7 @@ local function proto_V0_x(socket_inst, auth_key, magic) } local success, err = ltn12.pump.all(ltn12.source.string(data), socket_inst.sink) if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': opening socket') end local sink, buffer = ltn12.sink.table() @@ -30,13 +31,14 @@ local function proto_V0_x(socket_inst, auth_key, magic) success, err = ltn12.pump.all(socket_inst.source(1), sink) socket_inst.close() if not success then - return nil, err + return nil, errors.ReQLDriverError( + r, table.concat{table.concat(buffer), '\n', err, ': reading error'}) end - return nil, table.concat(buffer) + return nil, errors.ReQLDriverError(r, table.concat(buffer)) end success, err = ltn12.pump.step(socket_inst.source(1), sink) if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': reading response') end if table.concat(buffer) == 'SUCCESS\0' then -- We're good, finish setting up the connection @@ -51,15 +53,15 @@ function m.init(r) --- Depreciated implementation of RethinkDB handshake version 0.3. Supports -- server version 1.16+. Passed to proto_version connection option. Will be -- removed in driver version 2. - function r.proto_V0_3(_, socket_inst, auth_key) - return proto_V0_x(socket_inst, auth_key, '\62\232\117\95') + function r.proto_V0_3(_r, socket_inst, auth_key) + return proto_V0_x(_r, socket_inst, auth_key, '\62\232\117\95') end --- Depreciated implementation of RethinkDB handshake version 0.4. Supports -- server version 2.0+. Passed to proto_version connection option. Will be -- removed in driver version 2. - function r.proto_V0_4(_, socket_inst, auth_key) - return proto_V0_x(socket_inst, auth_key, '\32\45\12\64') + function r.proto_V0_4(_r, socket_inst, auth_key) + return proto_V0_x(_r, socket_inst, auth_key, '\32\45\12\64') end end diff --git a/src/rethinkdb/internal/current_handshake.lua b/src/rethinkdb/internal/current_handshake.lua index d1c1ad84..6d8d725f 100644 --- a/src/rethinkdb/internal/current_handshake.lua +++ b/src/rethinkdb/internal/current_handshake.lua @@ -5,6 +5,7 @@ -- @copyright Adam Grandquist 2016 local crypto = require('crypto') +local errors = require'rethinkdb.errors' local ltn12 = require('ltn12') local pbkdf2 = require'rethinkdb.internal.pbkdf' local protect = require'rethinkdb.internal.protect' @@ -39,7 +40,7 @@ local function bxor256(u, t) return string.char(unpack(res)) end -local function __compare_digest(a, b) +local function compare_digest(a, b) local result if string.len(a) == string.len(b) then @@ -56,6 +57,13 @@ local function __compare_digest(a, b) return result ~= 0 end +local function maybe_auth_err(r, err, append) + if 10 <= err.error_code and err.error_code <= 20 then + return nil, errors.ReQLAuthError(r, err.error .. append) + end + return nil, errors.ReQLDriverError(r, err.error .. append) +end + local function current_handshake(r, socket_inst, auth_key, user) local function send(data) local success, err = ltn12.pump.all(ltn12.source.string(data), socket_inst.sink) @@ -104,7 +112,7 @@ local function current_handshake(r, socket_inst, auth_key, user) local success, err = send'\195\189\194\52' if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': sending magic number') end -- Now we have to wait for a response from the server @@ -114,17 +122,17 @@ local function current_handshake(r, socket_inst, auth_key, user) local message message, err = get_message() if not message then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': in first response') end local response = protect(r.decode, message) if not response then - return nil, message + return nil, errors.ReQLDriverError(r, message .. ': in first response') end if not response.success then - return nil, response + return maybe_auth_err(r, response, ': in first response') end local nonce = r.b64(rand_bytes(18)) @@ -143,7 +151,7 @@ local function current_handshake(r, socket_inst, auth_key, user) authentication = 'n,,' .. client_first_message_bare } if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': encoding SCRAM challenge') end @@ -156,17 +164,17 @@ local function current_handshake(r, socket_inst, auth_key, user) message, err = get_message() if not message then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': in second response') end response, err = protect(r.decode, message) if not response then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': decoding second response') end if not response.success then - return nil, response + return maybe_auth_err(r, response, ': in second response') end -- the authentication property will need to be retained @@ -178,7 +186,7 @@ local function current_handshake(r, socket_inst, auth_key, user) end if string.sub(authentication.r, 1, string.len(nonce)) ~= nonce then - return nil, 'Invalid nonce' + return nil, errors.ReQLDriverError(r, 'Invalid nonce') end authentication.i = tonumber(authentication.i) @@ -188,7 +196,11 @@ local function current_handshake(r, socket_inst, auth_key, user) local salt = r.unb64(authentication.s) -- SaltedPassword := Hi(Normalize(password), salt, i) - local salted_password = pbkdf2('sha256', auth_key, salt, authentication.i, 32) + local salted_password, str_err = pbkdf2('sha256', auth_key, salt, authentication.i, 32) + + if not salted_password then + return nil, errors.ReQLDriverError(r, str_err) + end -- ClientKey := HMAC(SaltedPassword, "Client Key") local client_key = crypto.hmac.digest('sha256', 'Client Key', salted_password, true) @@ -224,7 +236,7 @@ local function current_handshake(r, socket_inst, auth_key, user) table.concat{client_final_message_without_proof, ',p=', r.b64(client_proof)} } if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': encoding SCRAM response') end -- wait for the third server challenge @@ -235,17 +247,17 @@ local function current_handshake(r, socket_inst, auth_key, user) -- } message, err = get_message() if not message then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': in third response') end response, err = protect(r.decode, message) if not response then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': decoding third response') end if not response.success then - return nil, response + return maybe_auth_err(r, response, ': in third response') end response_authentication = response.authentication .. ',' @@ -254,14 +266,17 @@ local function current_handshake(r, socket_inst, auth_key, user) end if not authentication.v then - return nil, response + return nil, errors.ReQLDriverError( + r, + message .. ': missing server signature' + ) end - if not __compare_digest(authentication.v, server_signature) then - return nil, response + if compare_digest(authentication.v, server_signature) then + return true end - return true + return nil, errors.ReQLAuthError(r, 'invalid server signature') end return current_handshake diff --git a/src/rethinkdb/internal/protocol.lua b/src/rethinkdb/internal/protocol.lua index 4483b7fb..a67a5187 100644 --- a/src/rethinkdb/internal/protocol.lua +++ b/src/rethinkdb/internal/protocol.lua @@ -4,6 +4,7 @@ -- @license Apache -- @copyright Adam Grandquist 2016 +local errors = require'rethinkdb.errors' local little_to_int = require'rethinkdb.internal.bytes_to_int'.little local int_to_little = require'rethinkdb.internal.int_to_bytes'.little local ltn12 = require('ltn12') @@ -110,11 +111,11 @@ local function protocol(socket_inst) local ctx = {buffer = ''} local filter = ltn12.filter.cycle(buffer_response, ctx) - local function write_socket(token, data) + local function write_socket(r, token, data) data = table.concat{int_to_little(token, 8), int_to_little(string.len(data), 4), data} local success, err = ltn12.pump.all(ltn12.source.string(data), socket_inst.sink) if not success then - return nil, err + return nil, errors.ReQLDriverError(r, err .. ': writing socket') end return token end @@ -136,24 +137,27 @@ local function protocol(socket_inst) end -- Assign token - local data = protect(r.encode, query) - return write_socket(get_token(), data) + local data, err = protect(r.encode, query) + if not data then + return nil, errors.ReQLDriverError(r, err .. ': encoding query') + end + return write_socket(r, get_token(), data) end - function protocol_inst.continue_query(token) - return write_socket(token, CONTINUE) + function protocol_inst.continue_query(r, token) + return write_socket(r, token, CONTINUE) end - function protocol_inst.end_query(token) - return write_socket(token, STOP) + function protocol_inst.end_query(r, token) + return write_socket(r, token, STOP) end - function protocol_inst.noreply_wait() - return write_socket(get_token(), NOREPLY_WAIT) + function protocol_inst.noreply_wait(r) + return write_socket(r, get_token(), NOREPLY_WAIT) end - function protocol_inst.server_info() - return write_socket(get_token(), SERVER_INFO) + function protocol_inst.server_info(r) + return write_socket(r, get_token(), SERVER_INFO) end function protocol_inst.source() diff --git a/src/rethinkdb/internal/socket.lua b/src/rethinkdb/internal/socket.lua index 4733ea5c..698585b3 100644 --- a/src/rethinkdb/internal/socket.lua +++ b/src/rethinkdb/internal/socket.lua @@ -4,6 +4,7 @@ -- @license Apache -- @copyright Adam Grandquist 2016 +local errors = require'rethinkdb.errors' local ssl = require('ssl') local socket_sink = require('socket').sink local socket_source = require('socket').source @@ -13,10 +14,10 @@ local function settimeout(socket, ...) end local function socket(r, host, port, ssl_params, timeout) - local raw_socket, init_err = r.tcp() + local raw_socket, err = r.tcp() if not raw_socket then - return nil, init_err + return nil, errors.ReQLDriverError(r, err .. ': opening socket') end local status = settimeout(raw_socket, timeout, 't') and @@ -24,27 +25,28 @@ local function socket(r, host, port, ssl_params, timeout) settimeout(raw_socket, timeout) if not status then - return nil, 'Failed to set timeout' + return nil, errors.ReQLDriverError(r, 'Failed to set timeout') end - status, init_err = raw_socket:connect(host, port) + status, err = raw_socket:connect(host, port) if not status then - return nil, init_err + return nil, errors.ReQLDriverError(r, err .. ': connecting socket') end if ssl_params then - raw_socket, init_err = ssl.wrap(raw_socket, ssl_params) + raw_socket, err = ssl.wrap(raw_socket, ssl_params) if not raw_socket then - return nil, init_err + return nil, errors.ReQLDriverError(r, err .. ': wrapping socket in ssl') end status = false while not status do - status, init_err = raw_socket:dohandshake() - if init_err == 'closed' then - return nil, init_err + status, err = raw_socket:dohandshake() + if err == 'closed' then + return nil, errors.ReQLDriverError( + r, 'socket closed durring ssl handshake') end end end From acc69c1413252d4b6592cd700a67175ae31a41ed Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 25 Dec 2016 09:42:29 -0800 Subject: [PATCH 17/19] Release v1.0.3 --- .travis.yml | 2 +- CHANGELOG.md | 12 ++++++++---- ...eql-1.0.2-0.rockspec => lua-reql-1.0.3-0.rockspec | 4 ++-- src/rethinkdb.lua | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) rename lua-reql-1.0.2-0.rockspec => lua-reql-1.0.3-0.rockspec (98%) diff --git a/.travis.yml b/.travis.yml index 66e8a236..0cd99772 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ before_install: - luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec install: - - luarocks build --only-deps lua-reql-1.0.2-0.rockspec + - luarocks build --only-deps lua-reql-1.0.3-0.rockspec before_script: - wget https://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb diff --git a/CHANGELOG.md b/CHANGELOG.md index 26b35f42..7ab32eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ +# 1.0.3 + +- Fix connection callbacks ignored on errors + # 1.0.2 -* Fix `ngx.socket` does not support the full LuaSocket api. +- Fix `ngx.socket` does not support the full LuaSocket api. # 1.0.1 -* Fix refused connections throwing nil table error. +- Fix refused connections throwing nil table error. # 1.0.0 -* Documented API -* Semantic versioning +- Documented API +- Semantic versioning diff --git a/lua-reql-1.0.2-0.rockspec b/lua-reql-1.0.3-0.rockspec similarity index 98% rename from lua-reql-1.0.2-0.rockspec rename to lua-reql-1.0.3-0.rockspec index 3f59826e..da071c4d 100644 --- a/lua-reql-1.0.2-0.rockspec +++ b/lua-reql-1.0.3-0.rockspec @@ -1,9 +1,9 @@ rockspec_format = '1.1' package = 'lua-reql' -version = '1.0.2-0' +version = '1.0.3-0' source = { url = 'git://github.com/grandquista/Lua-ReQL', - branch = 'v1.0.2', + branch = 'v1.0.3', } description = { summary = 'A Lua driver for RethinkDB.', diff --git a/src/rethinkdb.lua b/src/rethinkdb.lua index 45669a29..8d9b442c 100644 --- a/src/rethinkdb.lua +++ b/src/rethinkdb.lua @@ -35,7 +35,7 @@ local function new(driver_options) r.proto_V1_0 = current_handshake --- The loaded luarocks version string as a semver. - r.version = v'1.0.2' + r.version = v'1.0.3' r._VERSION = r.version connection.init(r) From eca188dead23cec28652a6a1aed6df6735f3a849 Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sat, 26 May 2018 18:13:20 -0700 Subject: [PATCH 18/19] Transition to https://github.com/RebirthDB/rebirthdb-lua. --- .gitignore | 2 + .luacheckrc | 23 +- .luacov | 1 - .travis.yml | 5 +- CHANGELOG.md | 4 + LICENSE | 4 +- README.md | 14 +- config.ld | 5 +- ....3-0.rockspec => lua-reql-1.0.4-0.rockspec | 22 +- reql-1.0.4-0.rockspec | 76 +++++++ spec/control_spec.lua | 2 +- spec/json_parser_spec.lua | 2 +- src/rethinkdb.lua | 4 +- src/rethinkdb/internal/semver.lua | 206 ------------------ 14 files changed, 133 insertions(+), 237 deletions(-) rename lua-reql-1.0.3-0.rockspec => lua-reql-1.0.4-0.rockspec (80%) create mode 100644 reql-1.0.4-0.rockspec delete mode 100644 src/rethinkdb/internal/semver.lua diff --git a/.gitignore b/.gitignore index 7f6d73db..09063970 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ build # Testing rethinkdb_data/ t/servroot/ +here +ENV diff --git a/.luacheckrc b/.luacheckrc index 97b3d32b..42941f05 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,3 +1,24 @@ +stds.reql = { + read_globals = { + string = { + read_only = true, + fields = { + pack = {read_only = true}, + unpack = {read_only = true} + } + }, + table = { + read_only = true, + fields = { + unpack = {read_only = true} + } + } + } +} std = 'min' exclude_files = {'here'} -files['spec'] = {std = '+busted'} +files['spec'] = { + max_line_length = false, + std = '+busted' +} +files['src'] = {std = '+reql'} diff --git a/.luacov b/.luacov index 48ff3ca6..a9995ece 100644 --- a/.luacov +++ b/.luacov @@ -1,7 +1,6 @@ return { exclude = { 'src/rethinkdb/internal/protodef', - 'src/rethinkdb/internal/semver', }, include = {'src'}, } diff --git a/.travis.yml b/.travis.yml index 0cd99772..a08fb0a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,12 +32,13 @@ before_install: - hererocks here/$LUA_PATH -r^ --$LUA - source here/$LUA_PATH/bin/activate - luarocks install luacheck - - luacheck src + - luacheck . # Fix from https://github.com/leafo/lapis/issues/6 - luarocks install https://gist.githubusercontent.com/starius/b20d3e63929ae678c857/raw/4b4499f442337b6f577422364358590bd00c9d48/luacrypto-0.3.2-2.rockspec install: - - luarocks build --only-deps lua-reql-1.0.3-0.rockspec + - luarocks build --only-deps lua-reql-1.0.4-0.rockspec + - luarocks build reql-1.0.4-0.rockspec before_script: - wget https://download.rethinkdb.com/apt/pool/precise/main/r/rethinkdb/rethinkdb_${RDB_VER}precise_amd64.deb diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ab32eb9..54414f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.0.4 + +- Change source to https://github.com/RebirthDB/rebirthdb-lua + # 1.0.3 - Fix connection callbacks ignored on errors diff --git a/LICENSE b/LICENSE index fcb71aa3..aa561acc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,8 @@ -RethinkDB Lua Driver +RebirthDB Lua Driver Copyright 2010-2012 RethinkDB -Copyright 2014-2016 Adam Grandquist +Copyright 2014-2018 Adam Grandquist Licensed under the Apache License, Version 2.0 (the "License"); you may not use this product except in compliance with the License. diff --git a/README.md b/README.md index 92d8f476..d190e15f 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# Lua-ReQL +# RebirthDB-Lua -Rethinkdb driver in Lua -[![Build Status](https://travis-ci.org/grandquista/Lua-ReQL.svg?branch=master)](https://travis-ci.org/grandquista/Lua-ReQL) -[![Coverage Status](https://coveralls.io/repos/github/grandquista/Lua-ReQL/badge.svg?branch=master)](https://coveralls.io/github/grandquista/Lua-ReQL?branch=master) +RebirthDB driver in Lua +[![Build Status](https://travis-ci.org/RebirthDB/rebirthdb-lua.svg?branch=master)](https://travis-ci.org/RebirthDB/rebirthdb-lua) +[![Coverage Status](https://coveralls.io/repos/github/RebirthDB/rebirthdb-lua/badge.svg?branch=master)](https://coveralls.io/github/RebirthDB/rebirthdb-lua?branch=master) ## Installing - _IF USING LUA 5.1_ `luarocks install luabitop` -- `luarocks install lua-reql` +- `luarocks install reql` -See [Wiki](https://github.com/grandquista/Lua-ReQL/wiki) for documentation. +See [Wiki](https://github.com/RebirthDB/rebirthdb-lua/wiki) for documentation. ## Dev Dependencies - Lua >= 5.1 @@ -17,7 +17,7 @@ See [Wiki](https://github.com/grandquista/Lua-ReQL/wiki) for documentation. - luacheck - luacov - _IF USING LUA 5.1_ luabitop -- RethinkDB +- RebirthDB ## Testing - `luacheck .` diff --git a/config.ld b/config.ld index 9a05ab1f..4a9aa5d4 100644 --- a/config.ld +++ b/config.ld @@ -1,12 +1,11 @@ -project = 'Lua-ReQL' +project = 'RebirthDB-Lua' title = 'Lua-ReQL documentation' -description = 'A Lua driver for RethinkDB.' +description = 'A Lua driver for RebirthDB.' file = { 'src', exclude = { 'src/rethinkdb/internal/protodef.lua', - 'src/rethinkdb/internal/semver.lua', } } format = 'discount' diff --git a/lua-reql-1.0.3-0.rockspec b/lua-reql-1.0.4-0.rockspec similarity index 80% rename from lua-reql-1.0.3-0.rockspec rename to lua-reql-1.0.4-0.rockspec index da071c4d..72955ccb 100644 --- a/lua-reql-1.0.3-0.rockspec +++ b/lua-reql-1.0.4-0.rockspec @@ -1,13 +1,13 @@ rockspec_format = '1.1' package = 'lua-reql' -version = '1.0.3-0' +version = '1.0.4-0' source = { - url = 'git://github.com/grandquista/Lua-ReQL', - branch = 'v1.0.3', + url = 'git://github.com/RebirthDB/rebirthdb-lua', + branch = 'v1.0.4', } description = { summary = 'A Lua driver for RethinkDB.', - detailed = [[ + detailed = [===[ # Lua-ReQL Rethinkdb driver in Lua @@ -33,19 +33,20 @@ Rethinkdb driver in Lua ## Installing from source - `luarocks make` -[![Build Status](https://travis-ci.org/grandquista/Lua-ReQL.svg?branch=master)](https://travis-ci.org/grandquista/Lua-ReQL) +[![Build Status](https://travis-ci.org/RebirthDB/rebirthdb-lua.svg?branch=master)](https://travis-ci.org/RebirthDB/rebirthdb-lua) -[![Coverage Status](https://coveralls.io/repos/github/grandquista/Lua-ReQL/badge.svg?branch=master)](https://coveralls.io/github/grandquista/Lua-ReQL?branch=master) - ]], - homepage = 'https://github.com/grandquista/Lua-ReQL/wiki', +[![Coverage Status](https://coveralls.io/repos/github/RebirthDB/rebirthdb-lua/badge.svg?branch=master)](https://coveralls.io/github/RebirthDB/rebirthdb-lua?branch=master) + ]===], + homepage = 'https://github.com/RebirthDB/rebirthdb-lua/wiki', license = 'Apache', } dependencies = { 'lua >= 5.1, < 5.4', 'luacrypto ~> 0.3', - 'luasocket ~> 3.0', - 'luasec ~> 0.6', 'luajson ~> 1.3', + 'luasec ~> 0.6', + 'luasocket ~> 3.0', + 'semver ~> 1.2', } build = { type = 'builtin', @@ -69,7 +70,6 @@ build = { ['rethinkdb.internal.protect'] = 'src/rethinkdb/internal/protect.lua', ['rethinkdb.internal.protocol'] = 'src/rethinkdb/internal/protocol.lua', ['rethinkdb.internal.protodef'] = 'src/rethinkdb/internal/protodef.lua', - ['rethinkdb.internal.semver'] = 'src/rethinkdb/internal/semver.lua', ['rethinkdb.internal.socket'] = 'src/rethinkdb/internal/socket.lua', ['rethinkdb.internal.utilities'] = 'src/rethinkdb/internal/utilities.lua', } diff --git a/reql-1.0.4-0.rockspec b/reql-1.0.4-0.rockspec new file mode 100644 index 00000000..d03dd0d2 --- /dev/null +++ b/reql-1.0.4-0.rockspec @@ -0,0 +1,76 @@ +rockspec_format = '1.1' +package = 'reql' +version = '1.0.4-0' +source = { + url = 'git://github.com/RebirthDB/rebirthdb-lua', + branch = 'v1.0.4', +} +description = { + summary = 'A Lua driver for RebirthDB.', + detailed = [===[ +# RebirthDB-Lua + +RebirthDB driver in Lua + +## Installing +- _IF USING LUA 5.1_ `luarocks install luabitop` +- `luarocks install lua-reql` + +## Dev Dependencies +- Lua >= 5.1 +- Luarocks + - busted + - luacheck + - luacov + - _IF USING LUA 5.1_ luabitop +- RebirthDB + +## Testing +- `luacheck .` +- `busted -c` +- `luacov` + +## Installing from source +- `luarocks make` + +[![Build Status](https://travis-ci.org/RebirthDB/rebirthdb-lua.svg?branch=master)](https://travis-ci.org/RebirthDB/rebirthdb-lua) + +[![Coverage Status](https://coveralls.io/repos/github/RebirthDB/rebirthdb-lua/badge.svg?branch=master)](https://coveralls.io/github/RebirthDB/rebirthdb-lua?branch=master) + ]===], + homepage = 'https://github.com/RebirthDB/rebirthdb-lua/wiki', + license = 'Apache', +} +dependencies = { + 'lua >= 5.1, < 5.4', + 'luacrypto ~> 0.3', + 'luajson ~> 1.3', + 'luasec ~> 0.6', + 'luasocket ~> 3.0', + 'semver ~> 1.2', +} +build = { + type = 'builtin', + modules = { + reql = 'src/rethinkdb.lua', + ['reql.connection_instance'] = 'src/rethinkdb/connection_instance.lua', + ['reql.connection'] = 'src/rethinkdb/connection.lua', + ['reql.connector'] = 'src/rethinkdb/connector.lua', + ['reql.cursor'] = 'src/rethinkdb/cursor.lua', + ['reql.depreciate'] = 'src/rethinkdb/depreciate.lua', + ['reql.errors'] = 'src/rethinkdb/errors.lua', + ['reql.reql'] = 'src/rethinkdb/reql.lua', + ['reql.rtype'] = 'src/rethinkdb/rtype.lua', + ['reql.internal.bits51'] = 'src/rethinkdb/internal/bits51.lua', + ['reql.internal.bits53'] = 'src/rethinkdb/internal/bits53.lua', + ['reql.internal.bytes_to_int'] = 'src/rethinkdb/internal/bytes_to_int.lua', + ['reql.internal.convert_pseudotype'] = 'src/rethinkdb/internal/convert_pseudotype.lua', + ['reql.internal.current_handshake'] = 'src/rethinkdb/internal/current_handshake.lua', + ['reql.internal.int_to_bytes'] = 'src/rethinkdb/internal/int_to_bytes.lua', + ['reql.internal.pbkdf'] = 'src/rethinkdb/internal/pbkdf.lua', + ['reql.internal.protect'] = 'src/rethinkdb/internal/protect.lua', + ['reql.internal.protocol'] = 'src/rethinkdb/internal/protocol.lua', + ['reql.internal.protodef'] = 'src/rethinkdb/internal/protodef.lua', + ['reql.internal.socket'] = 'src/rethinkdb/internal/socket.lua', + ['reql.internal.utilities'] = 'src/rethinkdb/internal/utilities.lua', + } +} diff --git a/spec/control_spec.lua b/spec/control_spec.lua index 14930017..3a5d2978 100644 --- a/spec/control_spec.lua +++ b/spec/control_spec.lua @@ -5,7 +5,7 @@ local function reql_error_formatter(err) end end -local version = require('rethinkdb.internal.semver')(string.match(_VERSION, '%d+%.%d+')) +local version = require('semver')(string.match(_VERSION, '%d+%.%d+')) describe('control', function() local r diff --git a/spec/json_parser_spec.lua b/spec/json_parser_spec.lua index fd6d5dd3..32deeca3 100644 --- a/spec/json_parser_spec.lua +++ b/spec/json_parser_spec.lua @@ -5,7 +5,7 @@ local function reql_error_formatter(err) end end -local version = require('rethinkdb.internal.semver')(string.match(_VERSION, '%d+%.%d+')) +local version = require('semver')(string.match(_VERSION, '%d+%.%d+')) describe('control dkjson', function() local r diff --git a/src/rethinkdb.lua b/src/rethinkdb.lua index 8d9b442c..7e6cb9fc 100644 --- a/src/rethinkdb.lua +++ b/src/rethinkdb.lua @@ -19,7 +19,7 @@ local utilities = require'rethinkdb.internal.utilities' local reql = require'rethinkdb.reql' local rtype = require'rethinkdb.rtype' -local v = require('rethinkdb.internal.semver') +local v = require('semver') --- Creates an independent driver instance with the passed options. local function new(driver_options) @@ -35,7 +35,7 @@ local function new(driver_options) r.proto_V1_0 = current_handshake --- The loaded luarocks version string as a semver. - r.version = v'1.0.3' + r.version = v'1.0.4' r._VERSION = r.version connection.init(r) diff --git a/src/rethinkdb/internal/semver.lua b/src/rethinkdb/internal/semver.lua deleted file mode 100644 index 1b848820..00000000 --- a/src/rethinkdb/internal/semver.lua +++ /dev/null @@ -1,206 +0,0 @@ -local semver = { - _VERSION = '1.2.0', - _DESCRIPTION = 'semver for Lua', - _URL = 'https://github.com/kikito/semver.lua', - _LICENSE = [[ - MIT LICENSE - - Copyright (c) 2015 Enrique GarcĂ­a Cota - - Permission is hereby granted, free of charge, to any person obtaining a - copy of tother software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and tother permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ]] -} - -local function checkPositiveInteger(number, name) - assert(number >= 0, name .. ' must be a valid positive number') - assert(math.floor(number) == number, name .. ' must be an integer') -end - -local function present(value) - return value and value ~= '' -end - --- splitByDot("a.bbc.d") == {"a", "bbc", "d"} -local function splitByDot(str) - str = str or "" - local t, count = {}, 0 - str:gsub("([^%.]+)", function(c) - count = count + 1 - t[count] = c - end) - return t -end - -local function parsePrereleaseAndBuildWithSign(str) - local prereleaseWithSign, buildWithSign = str:match("^(-[^+]+)(+.+)$") - if not (prereleaseWithSign and buildWithSign) then - prereleaseWithSign = str:match("^(-.+)$") - buildWithSign = str:match("^(+.+)$") - end - assert(prereleaseWithSign or buildWithSign, ("The parameter %q must begin with + or - to denote a prerelease or a build"):format(str)) - return prereleaseWithSign, buildWithSign -end - -local function parsePrerelease(prereleaseWithSign) - if prereleaseWithSign then - local prerelease = prereleaseWithSign:match("^-(%w[%.%w-]*)$") - assert(prerelease, ("The prerelease %q is not a slash followed by alphanumerics, dots and slashes"):format(prereleaseWithSign)) - return prerelease - end -end - -local function parseBuild(buildWithSign) - if buildWithSign then - local build = buildWithSign:match("^%+(%w[%.%w-]*)$") - assert(build, ("The build %q is not a + sign followed by alphanumerics, dots and slashes"):format(buildWithSign)) - return build - end -end - -local function parsePrereleaseAndBuild(str) - if not present(str) then return nil, nil end - - local prereleaseWithSign, buildWithSign = parsePrereleaseAndBuildWithSign(str) - - local prerelease = parsePrerelease(prereleaseWithSign) - local build = parseBuild(buildWithSign) - - return prerelease, build -end - -local function parseVersion(str) - local sMajor, sMinor, sPatch, sPrereleaseAndBuild = str:match("^(%d+)%.?(%d*)%.?(%d*)(.-)$") - assert(type(sMajor) == 'string', ("Could not extract version number(s) from %q"):format(str)) - local major, minor, patch = tonumber(sMajor), tonumber(sMinor), tonumber(sPatch) - local prerelease, build = parsePrereleaseAndBuild(sPrereleaseAndBuild) - return major, minor, patch, prerelease, build -end - - --- return 0 if a == b, -1 if a < b, and 1 if a > b -local function compare(a,b) - return a == b and 0 or a < b and -1 or 1 -end - -local function compareIds(myId, otherId) - if myId == otherId then return 0 - elseif not myId then return -1 - elseif not otherId then return 1 - end - - local selfNumber, otherNumber = tonumber(myId), tonumber(otherId) - - if selfNumber and otherNumber then -- numerical comparison - return compare(selfNumber, otherNumber) - -- numericals are always smaller than alphanums - elseif selfNumber then - return -1 - elseif otherNumber then - return 1 - else - return compare(myId, otherId) -- alphanumerical comparison - end -end - -local function smallerIdList(myIds, otherIds) - local myLength = #myIds - local comparison - - for i=1, myLength do - comparison = compareIds(myIds[i], otherIds[i]) - if comparison ~= 0 then - return comparison == -1 - end - -- if comparison == 0, continue loop - end - - return myLength < #otherIds -end - -local function smallerPrerelease(mine, other) - if mine == other or not mine then return false - elseif not other then return true - end - - return smallerIdList(splitByDot(mine), splitByDot(other)) -end - -local methods = {} - -function methods:nextMajor() - return semver(self.major + 1, 0, 0) -end -function methods:nextMinor() - return semver(self.major, self.minor + 1, 0) -end -function methods:nextPatch() - return semver(self.major, self.minor, self.patch + 1) -end - -local mt = { __index = methods } -function mt:__eq(other) - return self.major == other.major and - self.minor == other.minor and - self.patch == other.patch and - self.prerelease == other.prerelease - -- notice that build is ignored for precedence in semver 2.0.0 -end -function mt:__lt(other) - if self.major ~= other.major then return self.major < other.major end - if self.minor ~= other.minor then return self.minor < other.minor end - if self.patch ~= other.patch then return self.patch < other.patch end - return smallerPrerelease(self.prerelease, other.prerelease) - -- notice that build is ignored for precedence in semver 2.0.0 -end --- This works like the "pessimisstic operator" in Rubygems. --- if a and b are versions, a ^ b means "b is backwards-compatible with a" --- in other words, "it's safe to upgrade from a to b" -function mt:__pow(other) - return self.major == other.major and - self.minor <= other.minor -end -function mt:__tostring() - local buffer = { ("%d.%d.%d"):format(self.major, self.minor, self.patch) } - if self.prerelease then table.insert(buffer, "-" .. self.prerelease) end - if self.build then table.insert(buffer, "+" .. self.build) end - return table.concat(buffer) -end - -local function new(major, minor, patch, prerelease, build) - assert(major, "At least one parameter is needed") - - if type(major) == 'string' then - major,minor,patch,prerelease,build = parseVersion(major) - end - patch = patch or 0 - minor = minor or 0 - - checkPositiveInteger(major, "major") - checkPositiveInteger(minor, "minor") - checkPositiveInteger(patch, "patch") - - local result = {major=major, minor=minor, patch=patch, prerelease=prerelease, build=build} - return setmetatable(result, mt) -end - -setmetatable(semver, { __call = function(_, ...) return new(...) end }) -semver._VERSION= semver(semver._VERSION) - -return semver From 0a51ee52923d826ed8d6877f6bdf7d9cfcdfc6dc Mon Sep 17 00:00:00 2001 From: Adam Grandquist Date: Sun, 27 May 2018 22:12:21 -0700 Subject: [PATCH 19/19] Fix merge conflict. --- .luacheckrc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 490628ef..42941f05 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -17,13 +17,8 @@ stds.reql = { } std = 'min' exclude_files = {'here'} -<<<<<<< HEAD files['spec'] = { max_line_length = false, std = '+busted' } files['src'] = {std = '+reql'} -======= -files['spec'] = {std = '+busted'} -max_line_length = 140 ->>>>>>> master