Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 1 addition & 9 deletions .github/scripts/bazel_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ BAZELISK_BUILD_CMD="${BAZELISK_CMD} build --noshow_progress --strategy=CppCompil
BAZELISK_RUN_CMD="${BAZELISK_CMD} run"

BAZEL_BINARY_TARGETS=(
"//:word_query"
"//:word_query_evolution"
"//:attention_broker_service"
"//:attention_broker_client"
"//:das"
"//:db_loader"
"//:busnode"
"//:busclient"
"//:database_adapter"
"//:ci_binaries"
)

BAZEL_BINARY_OUTPUTS=(
Expand Down
53 changes: 40 additions & 13 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,41 @@ jobs:
- name: Loading Load Knowledge Base
run: das-cli metta load /tmp/animals.metta

- name: Setup bazel
run: .github/scripts/setup_bazel.sh

- name: Compile Binaries
run: .github/scripts/bazel_build.sh

- name: Starting Attention Broker
run: das-cli attention-broker restart

- name: Starting MORK Server and Load Knowledge Base
- name: Starting MORK Servers
run: |-
make run-mork-server > /dev/null 2>&1 &

until curl --silent http://localhost:40022/status/-; do
echo "Waiting MORK…"
sleep 1
set -euo pipefail

make run-mork-server &
pid_40022=$!
DAS_MORK_PORT=40032 make run-mork-server &
pid_40032=$!

launch_failed=0
wait "${pid_40022}" || launch_failed=1
wait "${pid_40032}" || launch_failed=1
if [[ "${launch_failed}" -ne 0 ]]; then
echo "MORK server launch failed" >&2
docker ps -a --filter "name=das-mork-server-" >&2 || true
exit 1
fi

for port in 40022 40032; do
for attempt in $(seq 1 60); do
if curl --fail --silent --show-error "http://localhost:${port}/status/-"; then
echo "MORK ready on port ${port}"
break
fi
if [[ "${attempt}" -eq 60 ]]; then
echo "MORK failed to start on port ${port}" >&2
docker ps -a --filter "name=das-mork-server-${port}" >&2 || true
exit 1
fi
echo "Waiting for MORK on port ${port}…"
sleep 1
done
done
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- name: Starting Postgres Server and load database
Expand All @@ -87,5 +106,13 @@ jobs:

docker exec -i pg_test psql -U postgres -d postgres_wrapper_test < src/scripts/postgres_setup.sql

- name: Setup bazel
run: .github/scripts/setup_bazel.sh

- name: Execute Unit Test Suite
run: make run-tests-only
working-directory: ./src
run: ./scripts/bazel_exec.sh test --show_progress --cache_test_results=no //tests/cpp/...

- name: Build production binaries
working-directory: ./src
run: ./scripts/bazel_exec.sh build --noshow_progress //:ci_binaries
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ test-agents-integration:
run-tests-only:
@$(MAKE) bazel 'test --show_progress --cache_test_results=no //tests/...'

build-ci-binaries:
@cd src && ./scripts/bazel_exec.sh build --noshow_progress //:ci_binaries

run-tests-native:
@cd src && ./scripts/bazel_exec.sh test --show_progress --cache_test_results=no //tests/cpp/...

ci-unit-tests: run-tests-native build-ci-binaries

lint-all:
@$(MAKE) bazel lint \
"//... --fix --report --diff" \
Expand Down
8 changes: 4 additions & 4 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ common --color=yes
common --curses=yes
# common --show_timestamps

# Use half of all available CPU cores
common --jobs=HOST_CPUS*0.5
# Use 85% all available CPU cores
common --jobs=HOST_CPUS*0.85

# Enable bazel bzlmod (for Bazel 8+)
common --enable_bzlmod
Expand Down Expand Up @@ -45,8 +45,8 @@ build --host_cxxopt=-w
build --host_cxxopt=-Wno-all

#################################### TEST #####################################
# Use half of all available CPU cores
# test --jobs=HOST_CPUS*0.5
# Use 85% of all available CPU cores
# test --jobs=HOST_CPUS*0.85

# Other options
test --test_output=errors
Expand Down
20 changes: 20 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,23 @@ cc_binary(
"//main:bus_client_lib",
],
)

# Meta-target for CI: building this forces all production binaries to compile/link.
# Used by .github/workflows/run-unit-tests.yml and bazel_build.sh.
genrule(
name = "ci_binaries",
srcs = [
":word_query",
":word_query_evolution",
":attention_broker_service",
":attention_broker_client",
":das",
":db_loader",
":busnode",
":busclient",
":database_adapter",
],
outs = ["ci_binaries.stamp"],
cmd = "touch $@",
visibility = ["//visibility:public"],
)
20 changes: 8 additions & 12 deletions src/atomdb/morkdb/MorkDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,29 @@ httplib::Result MorkClient::send_request(const string& method, const string& pat
res = this->cli.Post(path, data, "text/plain");
}

if (!res) {
RAISE_ERROR("Connection error at http://" + this->base_url_ + path + ": " +
httplib::to_string(res.error()));
}

if (res->status == httplib::StatusCode::OK_200) {
return res;
}
if (!res || is_transient_mork_http_status(res->status)) {
string status_str = res ? std::to_string(res->status) : "unknown";

if (is_transient_mork_http_status(res->status)) {
if (attempt + 1 >= max_attempts) {
RAISE_ERROR("Http error at http://" + this->base_url_ + path + ": exhausted " +
std::to_string(max_attempts) + " retries, last status " +
std::to_string(res->status));
std::to_string(max_attempts) + " retries, last status " + status_str);
}

unsigned int delay_ms = initial_delay_ms;
for (unsigned int i = 0; i < attempt; ++i) {
delay_ms = static_cast<unsigned int>(delay_ms * backoff);
}

LOG_ERROR("MORK transient HTTP " << res->status << " at " << path << ", retrying (attempt "
LOG_ERROR("MORK transient HTTP " << status_str << " at " << path << ", retrying (attempt "
<< attempt + 1 << "/" << max_attempts << ")");
Utils::sleep(delay_ms);
continue;
}

if (res->status == httplib::StatusCode::OK_200) {
return res;
}

Comment thread
ccgsnet marked this conversation as resolved.
RAISE_ERROR("Http error at http://" + this->base_url_ + path + ": status " +
std::to_string(res->status));
}
Expand Down
18 changes: 7 additions & 11 deletions src/scripts/mork_server.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#!/bin/bash

set -eoux pipefail
set -euo pipefail

IMAGE_NAME="trueagi/das:mork-server-1.1.0"
CONTAINER_NAME="das-mork-server-$(date +%Y%m%d%H%M%S)"
MORK_PORT="${DAS_MORK_PORT:-40022}"
CONTAINER_NAME="das-mork-server-${MORK_PORT}"

docker run --rm \
docker rm -f "${CONTAINER_NAME}" 2>/dev/null || true

docker run -d --rm \
--name="${CONTAINER_NAME}" \
--network host \
-e MORK_SERVER_ADDR=0.0.0.0 \
-e MORK_SERVER_PORT=${DAS_MORK_PORT:-40022} \
-e MORK_SERVER_PORT="${MORK_PORT}" \
"${IMAGE_NAME}" "$@"

sleep 1

if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Removing existing container: ${CONTAINER_NAME}"
_=$(docker rm -f "${CONTAINER_NAME}" 2>&1 > /dev/null || true)
fi
6 changes: 3 additions & 3 deletions src/tests/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ cc_test(

cc_test(
name = "postgreswrapper_test",
size = "small",
size = "medium",
srcs = [
"postgreswrapper_test.cc",
],
Expand Down Expand Up @@ -971,7 +971,7 @@ cc_test(

cc_test(
name = "morkwrapper_test",
size = "small",
size = "medium",
srcs = [
"morkwrapper_test.cc",
],
Expand Down Expand Up @@ -1001,7 +1001,7 @@ cc_test(

cc_test(
name = "adapterdb_test",
size = "small",
size = "medium",
srcs = [
"adapterdb_test.cc",
],
Expand Down
4 changes: 2 additions & 2 deletions src/tests/cpp/adapterdb_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AdapterTestParams {
};

void seed_mork_adapter_test_data() {
auto mork_client = make_shared<MorkClient>("localhost:40022");
auto mork_client = make_shared<MorkClient>("localhost:40032");

const string similarity_seed = "(Similarity \"ent\" \"human\")";
const string inheritance_seed = "(Inheritance \"human\" \"mammal\")";
Expand Down Expand Up @@ -192,7 +192,7 @@ static const AdapterTestParams MorkParams = {
R"(
(Similarity "ent" $h)
(Inheritance "human" $m))",
{{"host", "localhost"}, {"port", 40022}},
{{"host", "localhost"}, {"port", 40032}},
"Mork",
};

Expand Down
4 changes: 2 additions & 2 deletions src/tests/cpp/morkdb_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST_F(MorkDBTest, QueryForTargets) {
}

TEST_F(MorkDBTest, ConcurrentQueryForPattern) {
const int num_threads = 200;
const int num_threads = 8;
vector<thread> threads;
atomic<int> success_count{0};

Expand Down Expand Up @@ -301,7 +301,7 @@ TEST_F(MorkDBTest, ConcurrentAddLinks) {
int arity = 3;
int chunck_size = 500;

const int num_threads = 100;
const int num_threads = 8;
vector<thread> threads;
atomic<int> success_count{0};

Expand Down
2 changes: 1 addition & 1 deletion src/tests/cpp/morkwrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace processor;
class MorkWrapperTest : public ::testing::Test {
protected:
string TEST_HOST = "localhost";
int TEST_PORT = 40022;
int TEST_PORT = 40032;

string INVALID_HOST = "invalid.host";
int INVALID_PORT = 99999;
Expand Down
1 change: 1 addition & 0 deletions src/tests/integration/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cc_test(
"-Iexternal/gtest/googletest",
],
linkstatic = 1,
tags = ["integration"],
deps = [
"//tests/integration/cpp/helpers:process_helper",
"//tests/integration/cpp/helpers:test_helper",
Expand Down
Loading