Skip to content

Commit d727e21

Browse files
authored
Add plugin unit/integration tests, optional for PR merge (#371)
* Add plugin unit/integration tests, optional for PR merge * install mold before plugin tests * try bundling * try to pass plugin unit tests * cant sudo bundle * try bundle * remove other bundler * use vendored bundler
1 parent a67f417 commit d727e21

3 files changed

Lines changed: 63 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ jobs:
166166
run: bash integration/complex/run.sh
167167
- name: Dry run
168168
run: bash integration/dry_run/run.sh
169-
# - name: Plugins
170-
# run: bash integration/plugins/run.sh
171169
- name: Ensure PgDog stopped
172170
run: |
173171
if pgrep -x pgdog > /dev/null; then
@@ -184,3 +182,59 @@ jobs:
184182
files: integration.lcov
185183
flags: integration
186184
fail_ci_if_error: true
185+
plugin-unit-tests:
186+
runs-on: blacksmith-4vcpu-ubuntu-2404
187+
continue-on-error: true
188+
steps:
189+
- uses: actions/checkout@v4
190+
- uses: actions-rs/toolchain@v1
191+
with:
192+
toolchain: stable
193+
override: true
194+
- uses: useblacksmith/rust-cache@v3
195+
with:
196+
prefix-key: "plugin-unit-v1"
197+
- name: Install CMake 3.31
198+
run: |
199+
sudo apt-get install -y mold
200+
sudo apt remove cmake
201+
sudo pip3 install cmake==3.31.6
202+
cmake --version
203+
- name: Install test dependencies
204+
run: cargo install cargo-nextest --version "0.9.78" --locked
205+
- name: Run plugin unit tests
206+
run: cargo nextest run -E 'package(pgdog-example-plugin)' --no-fail-fast
207+
plugin-integration-tests:
208+
runs-on: blacksmith-4vcpu-ubuntu-2404
209+
continue-on-error: true
210+
steps:
211+
- uses: actions/checkout@v4
212+
- uses: actions-rs/toolchain@v1
213+
with:
214+
toolchain: stable
215+
override: true
216+
- uses: useblacksmith/rust-cache@v3
217+
with:
218+
prefix-key: "plugin-integration-v1"
219+
- name: Setup PostgreSQL
220+
run: |
221+
sudo service postgresql start
222+
sudo -u postgres createuser --superuser --login $USER
223+
sudo -u postgres createdb $USER
224+
bash integration/setup.sh
225+
- name: Install dependencies
226+
run: |
227+
sudo apt update && sudo apt install -y python3-virtualenv mold
228+
sudo gem install bundler
229+
sudo apt remove -y cmake
230+
sudo pip3 install cmake==3.31.6
231+
cmake --version
232+
cargo install cargo-nextest --version "0.9.78" --locked
233+
- name: Build plugin
234+
run: |
235+
cargo build --release
236+
pushd plugins/pgdog-example-plugin
237+
cargo build --release
238+
popd
239+
- name: Run plugin integration tests
240+
run: bash integration/plugins/run.sh

integration/plugins/dev.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
set -e
33
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
44
pushd ${SCRIPT_DIR}
5+
bundle config set --local path vendor/bundle
6+
bundle install
57
bundle exec rspec *_spec.rb
68
popd

plugins/pgdog-example-plugin/src/plugin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ pub(crate) fn route_query(context: Context) -> Result<Route, PluginError> {
5555

5656
if let NodeEnum::RangeVar(RangeVar { relname, .. }) = table_name {
5757
// Got info on last write.
58-
if let Some(last_write) = { WRITE_TIMES.lock().get(relname).cloned() }
59-
&& last_write.elapsed() > Duration::from_secs(5)
60-
&& context.has_replicas()
61-
{
58+
if let Some(last_write) = { WRITE_TIMES.lock().get(relname).cloned() } {
59+
if last_write.elapsed() > Duration::from_secs(5) && context.has_replicas() {
60+
return Ok(Route::new(Shard::Unknown, ReadWrite::Read));
61+
}
62+
} else if context.has_replicas() {
6263
return Ok(Route::new(Shard::Unknown, ReadWrite::Read));
6364
}
6465
}

0 commit comments

Comments
 (0)