Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: integrate mysql (user-managed) into risedev and inline source tests #16449

Merged
merged 13 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,6 @@ echo "All processes has exited."
"""

[tasks.slt]
env = { SLT_HOST = "${RISEDEV_RW_FRONTEND_LISTEN_ADDRESS}", SLT_PORT = "${RISEDEV_RW_FRONTEND_PORT}", SLT_DB = "dev" }
category = "RiseDev - Test - SQLLogicTest"
install_crate = { version = "0.20.1", crate_name = "sqllogictest-bin", binary = "sqllogictest", test_arg = [
"--help",
Expand All @@ -1319,6 +1318,19 @@ command = "sqllogictest"
args = ["${@}"]
description = "🌟 Run SQLLogicTest"

[tasks.slt.env]
SLT_HOST = "${RISEDEV_RW_FRONTEND_LISTEN_ADDRESS}"
SLT_PORT = "${RISEDEV_RW_FRONTEND_PORT}"
SLT_DB = "dev"
PATH = "${PWD}/e2e_test/commands:${PATH}"

[tasks.slt-clean]
category = "RiseDev - Test - SQLLogicTest"
dependencies = ["clean-kafka", "reset-rw"]
description = "Run SQLLogicTest with a clean environment"
run_task = "slt"
args = ["${@}"]

[tasks.slt-streaming]
category = "RiseDev - Test - SQLLogicTest"
extend = "slt"
Expand Down Expand Up @@ -1433,3 +1445,14 @@ script = """
vars = dump_variables
echo ${vars}
"""

[tasks.show-risedev-env]
description = "Show risedev-env environment variables"
dependencies = ["check-risedev-env-file"]
script = '''
#!/usr/bin/env bash
set -euo pipefail
cat ${PREFIX_CONFIG}/risedev-env
echo "Hint: To load the environment variables into the shell, you may run:"
echo "$(tput setaf 4)\set -a; source ${PREFIX_CONFIG}/risedev-env; set +a$(tput sgr0)"
'''
18 changes: 6 additions & 12 deletions ci/scripts/e2e-source-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ buildkite-agent artifact download risingwave-connector.tar.gz ./
mkdir ./connector-node
tar xf ./risingwave-connector.tar.gz -C ./connector-node

echo "--- e2e, inline test"
risedev ci-start ci-inline-source-test
risedev slt './e2e_test/source_inline/**/*.slt'
echo "--- Kill cluster"
risedev ci-kill

echo "--- Prepare data"
cp src/connector/src/test_data/simple-schema.avsc ./avro-simple-schema.avsc
cp src/connector/src/test_data/complex-schema.avsc ./avro-complex-schema.avsc
Expand Down Expand Up @@ -82,15 +88,6 @@ echo "--- cdc share source test"
export MYSQL_HOST=mysql MYSQL_TCP_PORT=3306 MYSQL_PWD=123456
risedev slt './e2e_test/source/cdc/cdc.share_stream.slt'

# create a share source and check whether heartbeat message is received
risedev slt './e2e_test/source/cdc/cdc.create_source_job.slt'
table_id=$(psql -U root -h localhost -p 4566 -d dev -t -c "select id from rw_internal_tables where name like '%mysql_source%';" | xargs);
table_count=$(psql -U root -h localhost -p 4566 -d dev -t -c "select count(*) from rw_table(${table_id}, public);" | xargs);
if [ "$table_count" -eq 0 ]; then
echo "ERROR: internal table of cdc share source is empty!"
exit 1
fi
xxchan marked this conversation as resolved.
Show resolved Hide resolved

echo "--- mysql & postgres load and check"
risedev slt './e2e_test/source/cdc/cdc.load.slt'
# wait for cdc loading
Expand Down Expand Up @@ -168,9 +165,6 @@ echo "--- e2e, kafka alter source again"
./scripts/source/prepare_data_after_alter.sh 3
risedev slt './e2e_test/source/basic/alter/kafka_after_new_data_2.slt'

echo "--- e2e, inline test"
risedev slt './e2e_test/source_inline/**/*.slt'

echo "--- Run CH-benCHmark"
risedev slt './e2e_test/ch_benchmark/batch/ch_benchmark.slt'
risedev slt './e2e_test/ch_benchmark/streaming/*.slt'
8 changes: 8 additions & 0 deletions e2e_test/commands/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# "built-in" Sqllogictest system commands

Scripts (executables) in this directory are expected to be used as `system` commands in sqllogictests. You can use any language like bash, python, zx.

They will be loaded in `PATH` by `risedev slt`, and thus function as kind of "built-in" commands.

Only general commands should be put here.
If the script is ad-hoc (only used for one test), it's better to put next to the test file.
67 changes: 67 additions & 0 deletions e2e_test/commands/internal_table.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env zx

// zx: A tool for writing better scripts
// https://google.github.io/zx/

const {
name: job_name,
type: table_type,
count: count,
} = minimist(process.argv.slice(3), {
string: ["name", "type"],
boolean: ["count"],
});

// Return an array of CSV string
async function psql(query) {
return (
await $`
psql -h $RISEDEV_RW_FRONTEND_LISTEN_ADDRESS -p $RISEDEV_RW_FRONTEND_PORT -U root -d dev \
--csv --tuples-only -c ${query}
`
)
.toString()
.trim()
.split("\n")
.filter((line) => line.trim() != "");
}

// If `table_type` is null, return all internal tables for the job.
// If `job_name` is null, return all jobs' internal tables.
async function select_internal_table(job_name, table_type) {
// Note: if we have `t1`, and `t1_balabala`, the latter one will also be matched 😄.
const internal_tables = await psql(
`select name from rw_internal_tables where name like '__internal_${job_name}_%_${table_type}_%'`
);
if (internal_tables.length == 0) {
throw new Error(
`No internal tables found for the pattern '__internal_${job_name}_%_${table_type}_%'`
);
}

const res = new Map(
await Promise.all(
internal_tables.map(async (t) => {
let rows = await psql(`select * from ${t}`);
return [t, rows];
})
)
);
return res;
}

const tables = await select_internal_table(job_name, table_type);
for (const [table_name, rows] of tables) {
if (tables.size > 1) {
console.log(`Table: ${table_name}`);
}
if (count) {
console.log(`count: ${rows.length}`);
} else {
if (rows.length == 0) {
console.log("(empty)");
} else {
console.log(`${rows.join("\n")}`);
}
}
}
15 changes: 0 additions & 15 deletions e2e_test/source/cdc/cdc.create_source_job.slt

This file was deleted.

2 changes: 2 additions & 0 deletions e2e_test/source/cdc/mysql_cdc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ VALUES (1,1,'no'),
(3,3,'no'),
(4,4,'no');

-- This user is for non-shared CDC
CREATE USER 'dbz'@'%' IDENTIFIED BY '123456';
GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'dbz'@'%';

-- This user is for shared CDC
CREATE USER 'rwcdc'@'%' IDENTIFIED BY '123456';
GRANT SELECT, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'rwcdc'@'%';

Expand Down
133 changes: 0 additions & 133 deletions e2e_test/source/cdc_inline/mysql/mysql_create_drop.slt
xxchan marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

4 changes: 2 additions & 2 deletions e2e_test/source_inline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ risedev slt 'e2e_test/source_inline/**/*.slt'
To write tests, please ensure each file is self-contained and does not depend on running external scripts to setup the environment.

Use `system` command to setup instead.
For simple cases, you can directly write a bash command;
For more complex cases, you can write a test script (with any language like bash, python, zx), and invoke it in the `system` command.
- For simple cases, you can directly write a bash command;
- For more complex cases, you can write a test script. See also [e2e_test/commands/README.md](../commands/README.md)
Loading
Loading