Skip to content

Commit

Permalink
build: use locally-installed redis instead of dockerized one (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Jul 6, 2020
1 parent ca83509 commit 865842b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 26 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
steps:
- uses: actions/checkout@v1
- name: Install Deno
Expand All @@ -29,6 +24,15 @@ jobs:
- name: Run lint
run: |
make lint
- name: Install and start Redis
run: |
make testdeps
make start-redis
sleep 1
echo "::add-path::./testdata/redis/src"
- name: Run Tests
run: |
make test
- name: Kill Redis
run: |
make kill-redis
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
deno.d.ts
.idea
commands
commands
testdata/*/
51 changes: 50 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
TESTDATA_DIR=testdata

redis:
docker run -p 6379:6379 -d -t redis:5
test:
deno test -A *_test.ts
lint:
deno fmt --check
deno lint --unstable
deno lint --unstable

# The following targets are adopted from go-redis (https://github.com/go-redis/redis/blob/dc52593c8c63bc2a05796ec44efd317fd3e14b64/Makefile):
# * `testdeps`
# * `${TESTDATA_DIR}/redis`
# * `${TESTDATA_DIR}/redis/src/redis-server`
#
# Copyright (c) 2013 The github.com/go-redis/redis Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
testdeps: ${TESTDATA_DIR}/redis/src/redis-server

.PHONY: testdeps

${TESTDATA_DIR}/redis:
mkdir -p $@
wget -qO- http://download.redis.io/releases/redis-6.0.5.tar.gz | tar xvz --strip-components=1 -C $@

${TESTDATA_DIR}/redis/src/redis-server: ${TESTDATA_DIR}/redis
cd $< && make all

start-redis:
${TESTDATA_DIR}/redis/src/redis-server --port 6379 --daemonize yes

kill-redis:
${TESTDATA_DIR}/redis/src/redis-cli -p 6379 shutdown
26 changes: 7 additions & 19 deletions pubsub_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
assertThrowsAsync,
} from "./vendor/https/deno.land/std/testing/asserts.ts";
import { delay } from "./vendor/https/deno.land/std/async/mod.ts";
import { startRedisServer } from "./tests/test_util.ts";

import { connect } from "./redis.ts";
const { test } = Deno;
Expand Down Expand Up @@ -96,11 +97,9 @@ test({

const throwawayRedisServerPort = 6464;
let promiseList;
let throwawayRedisServerChildProcess = createThrowawayRedisServer(
throwawayRedisServerPort,
);

await delay(500);
let throwawayRedisServerChildProcess = await startRedisServer({
port: throwawayRedisServerPort,
});

const redisClient = await connect(
{ ...addr, name: "Main", port: throwawayRedisServerPort },
Expand Down Expand Up @@ -149,11 +148,10 @@ test({
"Too many messages were published.",
);

throwawayRedisServerChildProcess = createThrowawayRedisServer(
throwawayRedisServerPort,
);
throwawayRedisServerChildProcess = await startRedisServer({
port: throwawayRedisServerPort,
});

await delay(500);
const temporaryRedisClient = await connect(
{ ...addr, port: throwawayRedisServerPort },
);
Expand Down Expand Up @@ -186,13 +184,3 @@ test({
redisClient.close();
},
});

function createThrowawayRedisServer(port: number) {
return Deno.run(
{
cmd: ["redis-server", "--port", port.toString()],
stdin: "null",
stdout: "null",
},
);
}
24 changes: 24 additions & 0 deletions tests/test_util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Redis, connect, RedisConnectOptions } from "../redis.ts";
import { assert } from "../vendor/https/deno.land/std/testing/asserts.ts";
import { delay } from "../vendor/https/deno.land/std/async/mod.ts";

function* dbIndex() {
let i = 0;
Expand Down Expand Up @@ -36,3 +37,26 @@ export async function makeTest(
};
return { test, client, opts };
}

interface StartRedisServerOptions {
port: number;
}
export async function startRedisServer(
options: StartRedisServerOptions,
): Promise<Deno.Process> {
const { port } = options;
const process = Deno.run(
{
cmd: ["redis-server", "--port", port.toString()],
stdin: "null",
stdout: "null",
},
);
await waitForPort(port);
return process;
}

// FIXME!
function waitForPort(_port: number): Promise<void> {
return delay(500);
}

0 comments on commit 865842b

Please sign in to comment.