Skip to content
Permalink
Browse files

Merge branch 'autotest' into master

  • Loading branch information...
YihaoPeng committed Jun 7, 2019
2 parents 89d7eb4 + 9a6d309 commit 7e8ec903ed352845c41d79c3e6c6ad36cd700019
@@ -13,7 +13,7 @@ FROM ${BASE_IMAGE} as build
LABEL maintainer="Hanjiang Yu <hanjiang.yu@bitmain.com>"

ARG BUILD_JOBS=1
ARG BUILD_TESTING=OFF
ARG BUILD_TESTING=ON
ARG BUILD_TYPE=Release
ARG USER_DEFINED_COINBASE=OFF
ARG USER_DEFINED_COINBASE_SIZE=10
@@ -34,8 +34,7 @@ RUN mkdir -p /tmp/build && cd /tmp/build && cmake \
-DPOOL__USER_DEFINED_COINBASE=${USER_DEFINED_COINBASE} \
-DPOOL__WORK_WITH_STRATUM_SWITCHER=${WORK_WITH_STRATUM_SWITCHER} \
/tmp/btcpool
RUN cd /tmp/build && make -j${BUILD_JOBS}
RUN cd /tmp/build && make package && mkdir -p /work/package && cp *.deb /work/package/
RUN cd /tmp/build && make package -j${BUILD_JOBS} && mkdir -p /work/package && cp *.deb /work/package/

######### Release image #########
FROM ubuntu:18.04
@@ -68,9 +67,7 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*

# startup scripts
COPY ./docker/btcpool/deploy/entrypoint.sh /
COPY ./docker/btcpool/deploy/wait-for-it.sh /
RUN chmod +x /entrypoint.sh /wait-for-it.sh
COPY ./docker/btcpool/deploy/entrypoint.sh ./docker/btcpool/deploy/wait-for-it.sh /

# entrypoint
ENTRYPOINT ["/entrypoint.sh"]
No changes.
No changes.
@@ -25,6 +25,8 @@ services:
userlist:
build:
context: ../userlist-api
args:
APT_MIRROR_URL: $APT_MIRROR_URL

gbtmaker:
depends_on:
@@ -49,7 +51,7 @@ services:
- userlist
image: btccom/btcpool-btc
ports:
- 3333:3333
- 53333:3333
volumes:
- ./cfg:/work/config
command: /wait-for-it.sh kafka:9092 -- /wait-for-it.sh userlist:80 -- sserver -c /work/config/sserver.cfg
@@ -60,7 +62,7 @@ services:
- userlist
image: btccom/btcpool-btc
ports:
- 3334:3334
- 53334:3334
volumes:
- ./cfg:/work/config
command: /wait-for-it.sh kafka:9092 -- /wait-for-it.sh userlist:80 -- sserver -c /work/config/sserver-simulator.cfg
@@ -0,0 +1,13 @@
#!/bin/bash

# Wait for the container to run
# arg1: container name
# arg2...: args of wait-for-it.sh
WAIT_FOR_IT() {
container_name="$1"
shift 1
while ! docker inspect -f '{{.State.Running}}' "$container_name" &>/dev/null; do
sleep 1
done
docker exec "$container_name" /wait-for-it.sh "$@"
}
@@ -0,0 +1,191 @@
<?php
require_once __DIR__.'/functions.php';
set_error_handler('exitOnWarning');
if ($argc < 3) {
exitln("Usage:\n$argc[0] <json-lines-file> <stratum-server-host:port>");
}
$running = true;
$path = $argv[1];
$host = $argv[2];
$testData = parseStratumLines($path);
//echo json_encode($testData);die;
$fp = stream_socket_client($host, $errno, $errstr, 5);
if (!$fp) {
exitln("Cannot connect to $host: $errstr");
}
writeToServer($fp, json_encode($testData['mining.subscribe'])."\n".json_encode($testData['mining.authorize'])."\n");
$requestNum = 2;
$responseNum = 0;
for ($readLines=0; $readLines<100; $readLines++) {
$line = fgets($fp);
$line = trim($line);
$data = json_decode($line, true);
$id = $data['id'];
if (isset($data['method'])) {
$method = $data['method'];
switch ($method) {
case 'mining.notify':
$jobId = $data['params'][0];
$hash = computeJobHash($data);
echo "[INFO] New notify $hash from server\n";
if (!isset($testData['notify'][$hash])) {
continue;
}
if (!empty($testData['submit'][$hash])) {
$jsonLines = '';
foreach ($testData['submit'][$hash] as $submit) {
$submitData = $testData['request'][$submit['id']]['request'];
$submitData['params'][1] = $jobId;
$jsonLines .= json_encode($submitData)."\n";
}
writeToServer($fp, $jsonLines);
$shareNum = count($testData['submit'][$hash]);
echo "[INFO] Submit ", $shareNum, " to server\n";
$requestNum += $shareNum;
unset($testData['submit'][$hash]);
}
}
continue;
}
if (!isset($testData['request'][$id])) {
exitln("Cannot find the request $id from testData of the response $line");
}
$request = $testData['request'][$id];
if ($request['response']['result'] != $data['result']) {
exitln("Unexpected response of request '$id': ".json_encode($request['request'])."\nIt should be: ".json_encode($request['response'])."\nBut got this: $line");
}
$responseNum++;
if (empty($testData['submit']) && ($requestNum == $responseNum)) {
break;
}
}
if (!empty($testData['submit'])) {
exitln("Missing 'mining.notify' of these submissions: ".json_encode($testData['submit']));
}
if ($requestNum != $responseNum) {
exitln("Request number ($requestNum) != Response number ($responseNum)");
}
echo "[INFO] Sent $requestNum requests to server and got $responseNum responses\n";
echo "[INFO] All checking past\n";
fclose($fp);
//----------------------------------------------
function writeToServer($fp, $json) {
$jsonLen = strlen($json);
$len = fwrite($fp, $json);
if ($len != $jsonLen) {
exitln("Short write to server, should write $jsonLen bytes but only $len bytes be written");
}
}
function parseStratumLines($path) {
$result = [
'request' => [],
'notify' => [],
'submit' => [],
];
$notifyCache = [];
$lines = file($path);
if (empty($lines)) {
exitln("Cannot load $file");
}
foreach ($lines as $line) {
$line = trim($line);
$data = json_decode($line, true);
$id = $data['id'];
if (isset($data['method'])) {
$method = $data['method'];
if ($id !== null) {
$result['request'][$id] = [
'method' => $method,
'request' => $data,
];
}
switch ($method) {
case 'mining.subscribe':
$result[$method] = $data;
break;
case 'mining.authorize':
$result[$method] = $data;
$result['usr'] = $data['params'][0];
$result['pwd'] = $data['params'][1];
break;
case 'mining.notify':
$jobId = $data['params'][0];
$hash = computeJobHash($data);
$result['notify'][$hash] = [
'job' => $data,
'job_id' => $jobId,
];
$notifyCache[$jobId] = $hash;
break;
case 'mining.submit':
$jobId = $data['params'][1];
if (!isset($notifyCache[$jobId])) {
exitln("Wrong test data, cannot find stratum job of the submit $line");
}
$jobHash = $notifyCache[$jobId];
if (!isset($result['submit'][$hash])) {
$result['submit'][$hash] = [];
}
$result['submit'][$hash][] = [
'id' => $id,
'job_id' => $jobId,
];
break;
}
continue;
}
if (!isset($result['request'][$id])) {
exitln("Wrong test data, cannot find request of the response $line");
}
if (isset($result['request'][$id]['response'])) {
exitln("Wrong test data, duplicated response $line of the request $id");
}
$result['request'][$id]['response'] = $data;
}
if (!isset($result['mining.subscribe']) || !isset($result['mining.authorize'])) {
exitln("Wrong test data, missing mining.subscribe or mining.authorize");
}
return $result;
}
function computeJobHash($data) {
$params = $data['params'];
$text = implode ('|', [$params[1], $params[2], $params[3], $params[5], $params[6], $params[7]]);
$text .= '|'.implode(',', $params[4]);
return sha1($text);
}
@@ -4,8 +4,17 @@
export BASE_DIR="$( cd "$( dirname "$0" )" && pwd )"
export STDOUT="/tmp/btcpool-test-btc-stdout.log"
export LOGFILE="/tmp/btcpool-test-btc-result.log"
export ARG_STORE="/tmp/btcpool-test-btc-argstore.conf"

source $ARG_STORE 2>/dev/null

echo -n >$STDOUT
echo -n >$ARG_STORE

# stored args
if [ "x$APT_MIRROR_URL" != "x" ]; then
echo "export APT_MIRROR_URL='$APT_MIRROR_URL'" >> $ARG_STORE
fi

echo "View logs:"
echo " tail -F $STDOUT"
@@ -3,14 +3,24 @@ set -e

DOCKER_COMPOSE="docker-compose --no-ansi"

echo "build base image..."
cd "$BASE_DIR/../../base-image"
docker build -t btccom/btcpool_build:btc-0.16.3 -f Dockerfile.btc --build-arg BUILD_JOBS=$(nproc) . >>$STDOUT
echo "done"
BUILD_ARGS="--build-arg BUILD_JOBS=$(nproc) --build-arg BUILD_TESTING=ON"
if [ "x$APT_MIRROR_URL" != "x" ]; then
BUILD_ARGS="$BUILD_ARGS --build-arg APT_MIRROR_URL=$APT_MIRROR_URL"
fi
if [ "x$NO_CACHE" != "x" ]; then
BUILD_ARGS="$BUILD_ARGS --no-cache"
fi

if [ "$BUILD_BASE_IMAGE" != "" ]; then
echo "build base image..."
cd "$BASE_DIR/../../base-image"
docker build -t btccom/btcpool_build:btc-0.16.3 -f Dockerfile.btc $BUILD_ARGS . >>$STDOUT
echo "done"
fi

echo "build BTCPool-BTC image..."
cd "$BASE_DIR/../../deploy"
docker build -t btccom/btcpool-btc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:btc-0.16.3 --build-arg BUILD_JOBS=$(nproc) ../../.. >>$STDOUT
docker build -t btccom/btcpool-btc -f Dockerfile $BUILD_ARGS --build-arg BASE_IMAGE=btccom/btcpool_build:btc-0.16.3 ../../.. >>$STDOUT
echo "done"

echo "build docker compose..."
@@ -1,11 +1,13 @@
#!/bin/bash
set -e
source "$BASE_DIR/helper/functions.sh"

PID=$$
MAIN_CONTAINER_NAME="btc_gbtmaker_1"
KAFKA_RESULT="/tmp/btcpool-test-gbtmaker.$PID.log"
KAFKA_CONSUMER="docker exec btc_kafka_1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092"
BITCOIN_CLI="docker exec btc_bitcoind_1 bitcoin-cli -datadir=/work/bitcoin1 -rpcclienttimeout=5"
WAIT_FOR_IT="$BASE_DIR/../../deploy/wait-for-it.sh"
WAIT_FOR_IT="WAIT_FOR_IT $MAIN_CONTAINER_NAME"
DOCKER_COMPOSE="docker-compose --no-ansi"

cd "$BASE_DIR"
@@ -16,6 +18,7 @@ $DOCKER_COMPOSE down >>$STDOUT
echo "start gbtmaker (5s)..."
$DOCKER_COMPOSE up gbtmaker >>$STDOUT &
sleep 5
$WAIT_FOR_IT kafka:9092

{
echo "generate new blocks in the background..."
@@ -1,11 +1,13 @@
#!/bin/bash
set -e
source "$BASE_DIR/helper/functions.sh"

PID=$$
MAIN_CONTAINER_NAME="btc_jobmaker_1"
KAFKA_RESULT="/tmp/btcpool-test-jobmaker.$PID.log"
KAFKA_CONSUMER="docker exec btc_kafka_1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092"
KAFKA_PRODUCER="docker exec -i btc_kafka_1 /opt/kafka/bin/kafka-console-producer.sh --broker-list kafka:9092"
WAIT_FOR_IT="$BASE_DIR/../../deploy/wait-for-it.sh"
WAIT_FOR_IT="WAIT_FOR_IT $MAIN_CONTAINER_NAME"
DOCKER_COMPOSE="docker-compose --no-ansi"

cd "$BASE_DIR"
@@ -16,6 +18,7 @@ $DOCKER_COMPOSE down >>$STDOUT
echo "start jobmaker (5s)..."
$DOCKER_COMPOSE up jobmaker >>$STDOUT &
sleep 5
$WAIT_FOR_IT kafka:9092

outputTestData() {
cat "$BASE_DIR/testdata/rawgbts-1.log" \
@@ -29,17 +32,20 @@ outputTestData() {
done
}

{
echo "send RawGbts in the background..."
outputTestData | $KAFKA_PRODUCER --topic RawGbt
echo "send RawGbts finished"
} &
echo "send RawGbts in the background..."
outputTestData | $KAFKA_PRODUCER --topic RawGbt &
KAFKA_PRODUCER_PID=$!

echo "consome StratumJob from kafka (60s)..."
$KAFKA_CONSUMER --topic StratumJob --from-beginning >$KAFKA_RESULT &
KAFKA_CONSUMER_PID=$!
sleep 60
kill $KAFKA_CONSUMER_PID
kill $KAFKA_PRODUCER_PID || echo "Kafka producer exited"
kill $KAFKA_CONSUMER_PID || {
echo "Kafka consumer exited too early"
head $SSERVER_RESULT
exit 1
}

line=`cat $KAFKA_RESULT | wc -l`
if [ $line -lt 20 ]; then

0 comments on commit 7e8ec90

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