Skip to content
Permalink
Browse files

Try to create an automated integration test environment (test of BTC …

…gbtmaker, jobmaker are available)
  • Loading branch information...
SwimmingTiger committed Apr 18, 2019
1 parent 4c121d0 commit be9fd1f0b2513ce5ce158be4e8c4293f29b97fe6
Showing with 2,427 additions and 5 deletions.
  1. +15 −0 .dockerignore
  2. +0 −3 CMakeLists.txt
  3. +3 −0 docker/btcpool/base-image/README.md
  4. +6 −2 docker/btcpool/deploy/Dockerfile
  5. +24 −0 docker/btcpool/deploy/README.md
  6. +201 −0 docker/btcpool/deploy/wait-for-it.sh
  7. +56 −0 docker/btcpool/test/btc/bitcoind/Dockerfile
  8. +16 −0 docker/btcpool/test/btc/bitcoind/bitcoin1.conf
  9. +16 −0 docker/btcpool/test/btc/bitcoind/bitcoin2.conf
  10. +6 −0 docker/btcpool/test/btc/bitcoind/logrotate-bitcoind
  11. +10 −0 docker/btcpool/test/btc/bitcoind/run-bitcoin1
  12. +10 −0 docker/btcpool/test/btc/bitcoind/run-bitcoin2
  13. +11 −0 docker/btcpool/test/btc/bitcoind/run-cli
  14. +10 −0 docker/btcpool/test/btc/bitcoind/sources-aliyun.com.list
  15. +42 −0 docker/btcpool/test/btc/cfg/blkmaker.cfg
  16. +33 −0 docker/btcpool/test/btc/cfg/gbtmaker.cfg
  17. +74 −0 docker/btcpool/test/btc/cfg/jobmaker.cfg
  18. +20 −0 docker/btcpool/test/btc/cfg/sharelogger.cfg
  19. +42 −0 docker/btcpool/test/btc/cfg/slparser.cfg
  20. +111 −0 docker/btcpool/test/btc/cfg/sserver-simulator.cfg
  21. +111 −0 docker/btcpool/test/btc/cfg/sserver.cfg
  22. +103 −0 docker/btcpool/test/btc/cfg/statshttpd.cfg
  23. +105 −0 docker/btcpool/test/btc/docker-compose.yml
  24. +53 −0 docker/btcpool/test/btc/helper/check-rawgbt.php
  25. +107 −0 docker/btcpool/test/btc/helper/check-stratumjob.php
  26. +82 −0 docker/btcpool/test/btc/helper/functions.php
  27. +24 −0 docker/btcpool/test/btc/run-test.sh
  28. +23 −0 docker/btcpool/test/btc/testcase/0000-build-image
  29. +4 −0 docker/btcpool/test/btc/testcase/0005-unittest
  30. +46 −0 docker/btcpool/test/btc/testcase/0010-test-gbtmaker
  31. +54 −0 docker/btcpool/test/btc/testcase/0011-test-jobmaker
  32. +5 −0 docker/btcpool/test/btc/testdata/rawgbts-1.log
  33. +37 −0 docker/btcpool/test/btc/testdata/rawgbts-2.log
  34. +5 −0 docker/btcpool/test/btc/testdata/rawgbts-3.log
  35. +2 −0 docker/btcpool/test/mysql/Dockerfile
  36. +70 −0 docker/btcpool/test/mysql/sql/bpool_local_db.sql
  37. +56 −0 docker/btcpool/test/mysql/sql/bpool_local_db_BEAM.sql
  38. +53 −0 docker/btcpool/test/mysql/sql/bpool_local_db_Bytom.sql
  39. +59 −0 docker/btcpool/test/mysql/sql/bpool_local_db_Decred.sql
  40. +60 −0 docker/btcpool/test/mysql/sql/bpool_local_db_ETH.sql
  41. +56 −0 docker/btcpool/test/mysql/sql/bpool_local_db_Grin.sql
  42. +106 −0 docker/btcpool/test/mysql/sql/bpool_local_stats_db.sql
  43. +20 −0 docker/btcpool/test/testosteron/LICENSE
  44. +92 −0 docker/btcpool/test/testosteron/README.md
  45. +173 −0 docker/btcpool/test/testosteron/testosteron
  46. +24 −0 docker/btcpool/test/userlist-api/Dockerfile
  47. +42 −0 docker/btcpool/test/userlist-api/public/autoreg.php
  48. +47 −0 docker/btcpool/test/userlist-api/public/user-list-coinbase-withtime.php
  49. +28 −0 docker/btcpool/test/userlist-api/public/usercoin.php
  50. +25 −0 docker/btcpool/test/userlist-api/public/userlist-autoreg.php
  51. +39 −0 docker/btcpool/test/userlist-api/public/userlist.php
  52. +10 −0 docker/btcpool/test/userlist-api/sources-aliyun.com.list
@@ -24,3 +24,18 @@ install/run_*/
/src/config/*.h
/src/*.pro.pb.h
/src/*.pro.pb.cc

# documents, tools and test scripts
/docker/
!/docker/btcpool/deploy/
/docs/
/tools/
/Dockerfile
/README.md
/.dockerignore
/.gitignore
/.clang-format
/run-clang-format.sh

# git folder
/.git/
@@ -640,17 +640,14 @@ endforeach()
# documents
install(FILES
LICENSE
README.md
COMPONENT
main
DESTINATION
${POOL__INSTALL_PREFIX})

# document dirss
install(DIRECTORY
docs
install
docker
COMPONENT
main
DESTINATION
@@ -49,4 +49,7 @@ docker build -t btccom/btcpool_build:ltc-0.16.3 -f Dockerfile.ltc --build-arg BU
# ZEC
docker build -t btccom/btcpool_build:zec-2.0.4 -f Dockerfile.zec --build-arg BUILD_JOBS=$(nproc) .
# Other chains (ETH, Beam, Grin, Decred, Bytom, ...)
# Please use BTC's base image.
```
@@ -57,6 +57,10 @@ RUN apt-get autoremove && \
apt-get autoclean && \
rm -rf /tmp/package /var/lib/apt/lists/*

# entrypoint
# startup scripts
COPY ./docker/btcpool/deploy/entrypoint.sh /
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
COPY ./docker/btcpool/deploy/wait-for-it.sh /
RUN chmod +x /entrypoint.sh /wait-for-it.sh

# entrypoint
ENTRYPOINT ["/entrypoint.sh"]
@@ -52,6 +52,9 @@ docker build -t btccom/btcpool-ltc -f Dockerfile --build-arg BASE_IMAGE=btccom/b
# ZEC
docker build -t btccom/btcpool-zec -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:zec-2.0.4 --build-arg BUILD_JOBS=$(nproc) ../../..
# Other chains (ETH, Beam, Grin, Decred, Bytom, ...)
# Please use BTC's image.
```

## Run unittest
@@ -74,4 +77,25 @@ docker run -it --rm btccom/btcpool-ltc unittest
# ZEC
docker run -it --rm btccom/btcpool-zec unittest
# Other chains (ETH, Beam, Grin, Decred, Bytom, ...)
# Same as BTC's command.
```

## Example: Running sserver

An example to show how to run a BTCPool's module in docker.

```
mkdir /work/config
cp '../../../src/eth/cfg/sserver(eth).cfg' '/work/config/sserver.cfg'
# Run container as a foreground process
docker run --rm --network=host -v=/work/config:/work/config btccom/btcpool-btc sserver -c /work/config/sserver.cfg
# Run container as a daemon
docker run --name=eth-sserver --network=host --restart=always -v=/work/config:/work/config -d btccom/btcpool-btc sserver -c /work/config/sserver.cfg
# Show logs
docker logs btc-sserver
```
@@ -0,0 +1,201 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
#
# From <https://github.com/vishnubob/wait-for-it>
#
# The MIT License (MIT)
# Copyright (c) 2016 Giles Hall
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this 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 this 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.

WAITFORIT_cmdname=${0##*/}

echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
else
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
fi
WAITFORIT_PID=$!
trap "kill -INT -$WAITFORIT_PID" INT
wait $WAITFORIT_PID
WAITFORIT_RESULT=$?
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
fi
return $WAITFORIT_RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
WAITFORIT_hostport=(${1//:/ })
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
shift 1
;;
--child)
WAITFORIT_CHILD=1
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
;;
-h)
WAITFORIT_HOST="$2"
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
WAITFORIT_HOST="${1#*=}"
shift 1
;;
-p)
WAITFORIT_PORT="$2"
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
WAITFORIT_PORT="${1#*=}"
shift 1
;;
-t)
WAITFORIT_TIMEOUT="$2"
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
WAITFORIT_TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
WAITFORIT_CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}

# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"

else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
fi

if [[ $WAITFORIT_CHILD -gt 0 ]]; then
wait_for
WAITFORIT_RESULT=$?
exit $WAITFORIT_RESULT
else
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
wait_for_wrapper
WAITFORIT_RESULT=$?
else
wait_for
WAITFORIT_RESULT=$?
fi
fi

if [[ $WAITFORIT_CLI != "" ]]; then
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
fi
exec "${WAITFORIT_CLI[@]}"
else
exit $WAITFORIT_RESULT
fi
@@ -0,0 +1,56 @@
#
# Dockerfile
#
# @author yihao.peng@bitmain.com
#
FROM phusion/baseimage:0.10.2
MAINTAINER YihaoPeng <yihao.peng@bitmain.com>

ENV HOME /root
ENV TERM xterm
CMD ["/sbin/my_init"]

# use aliyun source
ADD sources-aliyun.com.list /etc/apt/sources.list

RUN apt-get update
RUN apt-get install -y build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils python3
RUN apt-get install -y libboost-all-dev libzmq3-dev curl wget net-tools

# build bitcoind
RUN mkdir ~/source
RUN cd ~/source && wget https://github.com/bitcoin/bitcoin/archive/v0.16.3.tar.gz
RUN cd ~/source \
&& tar zxf v0.16.3.tar.gz && cd bitcoin-0.16.3 \
&& ./autogen.sh \
&& ./configure --disable-wallet --disable-tests \
&& make -j$(nproc) && make install

# mkdir bitcoind data dir
RUN mkdir -p /work/bitcoin1 /work/bitcoin2
RUN mkdir -p /root/scripts

# add config files
ADD bitcoin1.conf /work/bitcoin1/bitcoin.conf
ADD bitcoin2.conf /work/bitcoin2/bitcoin.conf

# logrotate
ADD logrotate-bitcoind /etc/logrotate.d/bitcoind

#
# services
#
# service for bitcoin1
RUN mkdir /etc/service/bitcoin1
ADD run-bitcoin1 /etc/service/bitcoin1/run
RUN chmod +x /etc/service/bitcoin1/run

# service for bitcoin1
RUN mkdir /etc/service/bitcoin2
ADD run-bitcoin2 /etc/service/bitcoin2/run
RUN chmod +x /etc/service/bitcoin2/run

# service for bitcoin-cli
#RUN mkdir /etc/service/bitcoin-cli
#ADD run-cli /etc/service/bitcoin-cli/run
#RUN chmod +x /etc/service/bitcoin-cli/run
@@ -0,0 +1,16 @@
regtest=1

port=8331
rpcport=8332

rpcuser=root
rpcpassword=root
rpcthreads=4

rpcallowip=172.16.0.0/12
rpcallowip=192.168.0.0/16
rpcallowip=10.0.0.0/8

addnode=127.0.0.1:18331

whitelistrelay=0
@@ -0,0 +1,16 @@
regtest=1

port=18331
rpcport=18332

rpcuser=root
rpcpassword=root
rpcthreads=4

rpcallowip=172.16.0.0/12
rpcallowip=192.168.0.0/16
rpcallowip=10.0.0.0/8

addnode=127.0.0.1:8331

whitelistrelay=0
@@ -0,0 +1,6 @@
/work/bitcoin1/debug.log /work/bitcoin1/testnet3/debug.log /work/bitcoin2/debug.log /work/bitcoin2/testnet3/debug.log {
daily
rotate 3
missingok
copytruncate
}

0 comments on commit be9fd1f

Please sign in to comment.
You can’t perform that action at this time.