Skip to content

Commit

Permalink
Streamline reset test run (#6)
Browse files Browse the repository at this point in the history
* Cleanup testing run

* Isolated test

* Pubber logging

* Adding restart count

* Empty Commit for Test

* Empty Commit for Test

* Empty Commit for Test

* Empty Commit for Test

* Empty Commit for Test

* Working reset test

* Empty Commit for Test

* Hourly cron

* Adjust to hourly

* Add always wait for config sync

* Fix recursion

* Fix config waiting
  • Loading branch information
grafnu committed Nov 7, 2022
1 parent 495eb06 commit af46c03
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 146 deletions.
114 changes: 6 additions & 108 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,9 @@ on:
push:
pull_request:
schedule:
- cron: '0 13 * * *'
- cron: '20 * * * *'

jobs:
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/setup-java@v1
with:
java-version: '11'
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Checkout source
uses: actions/checkout@v2.3.4
- name: Install dependencies
run: |
bin/setup_base
bin/clone_model
- name: code checks
if: ${{ always() }}
run: |
bin/gencode check
pubber/bin/build check
validator/bin/build check
- name: Schema conformance tests
if: ${{ always() }}
run: |
bin/test_schema -p
- name: simple trace test
run: |
bin/test_trace simple
- name: Registrar tests
if: ${{ always() }}
run: |
bin/test_registrar
bin/test_sites
redirect:
name: Endpoint Redirection
runs-on: ubuntu-latest
needs: udmi # Access to UDMI-REFLECTOR is mutually exclusive
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11'
- name: base setup
run: |
bin/setup_base
bin/clone_model
- name: pubber runs
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
bin/test_redirect $GCP_TARGET_PROJECT
- name: pubber cmd checks
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
echo ::::::: pubber.out.1
cat pubber.out.1
echo :::::::
echo Simple checks that a redirect happened and failed
fgrep registries/ZZ-TRI-FECTA/devices pubber.out.1
fgrep registries/missing/devices pubber.out.1
fgrep 'While waiting for connection start: Connection error' pubber.out.1
fgrep 'Endpoint connection restored to last working endpoint' pubber.out.1
- name: pubber config checks
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
echo ::::::: pubber.out.2
cat pubber.out.2
echo :::::::
echo Check the redirect-by-config setup
fgrep registries/ZZ-TRI-FECTA/devices pubber.out.2
fgrep registries/reconfigure/devices pubber.out.2
fgrep 'While waiting for connection start: Connection error' pubber.out.2
fgrep 'Endpoint connection restored to last working endpoint' pubber.out.2
fgrep 'Stopping system with extreme prejudice, restart true' pubber.out.2 # restart config
fgrep 'Stopping system with extreme prejudice, restart false' pubber.out.2 # auto-kill
fgrep 'Done with pubber run, exit code 193' pubber.out.2 # last_start auto-kill check
udmi:
name: Integration Tests
runs-on: ubuntu-latest
Expand All @@ -105,38 +20,21 @@ jobs:
run: |
bin/setup_base
bin/clone_model
- name: telemetry validator
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
bin/test_validator $GCP_TARGET_PROJECT
more /tmp/validator.out
echo Comparing test run results with golden file:
diff -u /tmp/validator.out etc/validator.out
- name: sequence tests
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
SEQUENCER_OPTS: ${{ secrets.SEQUENCER_OPTS }}
if: "${{ env.GCP_TARGET_PROJECT != '' }}"
run: |
bin/test_sequencer $GCP_TARGET_PROJECT
echo TAP sequencer.out-start
more /tmp/sequencer.out
echo TAP sequencer.out-end
diff -u /tmp/sequencer.out etc/sequencer.out
diff -u /tmp/generated.md docs/specs/sequences/generated.md
ls -1 sites/udmi_site_model/out/devices/AHU-1/tests/ | xargs -I% diff -u \
sites/udmi_site_model/out/devices/AHU-1/tests/%/sequence.md \
validator/sequences/%/sequence.md
- name: output logs
if: ${{ always() }}
run: |
cd sites/udmi_site_model/out && more `find . -type f` || true
- name: validator logs
if: ${{ always() }}
run: |
cat out/validator.out || true
- name: pubber logs
if: ${{ always() }}
run: |
echo TAP pubber.out-start
more pubber.out* out/pubber.out* || true
more pubber/out/*/*.json
more pubber/out/*/*.json || true
echo TAP pubber.out-start-end
8 changes: 4 additions & 4 deletions bin/test_sequencer
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if [[ $i -eq $WAITING ]]; then
false
fi

bin/sequencer $SEQUENCER_OPTS $site_path $project_id $device_id $serial_no
bin/sequencer $SEQUENCER_OPTS $site_path $project_id $device_id $serial_no endpoint_config_connection_success_reset
echo Completed execution of sequencer test run.

sed -i -e 's/.*sequencer RESULT/RESULT/' /tmp/sequencer.out
Expand All @@ -72,8 +72,8 @@ else
false
fi

generated=docs/specs/sequences/generated.md
cp $generated /tmp/ # Save for test/comparison later
bin/gencode_seq
#generated=docs/specs/sequences/generated.md
#cp $generated /tmp/ # Save for test/comparison later
#bin/gencode_seq

echo Done with base test_sequencer run.
16 changes: 1 addition & 15 deletions etc/sequencer.out
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
RESULT pass broken_config Sequence complete
RESULT pass device_config_acked Sequence complete
RESULT pass endpoint_config_connection_error Sequence complete
RESULT pass endpoint_config_connection_success_reconnect Sequence complete
RESULT pass extra_config Sequence complete
RESULT pass periodic_scan Sequence complete
RESULT pass self_enumeration Sequence complete
RESULT pass single_scan Sequence complete
RESULT pass system_last_update Sequence complete
RESULT pass system_min_loglevel Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass writeback_states Sequence complete
RESULT pass endpoint_config_connection_success_reset Sequence complete
12 changes: 9 additions & 3 deletions pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private void initializeDevice() {
deviceState.system.hardware = null;
}

markStateDirty(0);
markStateDirty();
}

private void initializePersistentStore() {
Expand All @@ -410,6 +410,10 @@ private File getPersistentStore() {
new File(siteModel.getDeviceWorkingDir(deviceId), PERSISTENT_STORE_FILE);
}

private void markStateDirty() {
markStateDirty(0);
}

private void markStateDirty(long delayMs) {
stateDirty.set(true);
if (delayMs >= 0) {
Expand Down Expand Up @@ -559,13 +563,15 @@ private void maybeRestartSystem() {
if (systemConfig == null) {
return;
}
info("maybeRestartSystem " + deviceState.system.mode + " " + systemConfig.mode);
info("maybeRestartSystem " + deviceState.system.mode + " " + systemConfig.mode
+ " " + persistentData.restart_count);
if (SystemMode.ACTIVE.equals(deviceState.system.mode)
&& SystemMode.RESTART.equals(systemConfig.mode)) {
restartSystem(true);
}
if (SystemMode.ACTIVE.equals(systemConfig.mode)) {
deviceState.system.mode = SystemMode.ACTIVE;
markStateDirty();
}
if (systemConfig.last_start != null && DEVICE_START_TIME.before(systemConfig.last_start)) {
System.err.printf("Device start time %s before last config start %s, terminating.",
Expand Down Expand Up @@ -889,7 +895,7 @@ private void removeBlobsetBlobState(SystemBlobsets blobId) {
if (deviceState.blobset.blobs.isEmpty()) {
deviceState.blobset = null;
}
markStateDirty(0);
markStateDirty();
}

private void maybeRedirectEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ protected void resetConfig() {
}

private void waitForConfigSync() {
untilTrue("device config sync", this::configUpdateComplete);
debug("waiting for config sync");
messageEvaluateLoop(this::configNotReady);
}

private Date syncConfig() {
protected Date syncConfig() {
updateConfig();
waitForConfigSync();
debug("config synced to " + JsonUtil.getTimestamp(deviceConfig.timestamp));
Expand Down Expand Up @@ -607,6 +608,7 @@ protected void updateConfig(String reason) {
updateConfig(SubFolder.BLOBSET, deviceConfig.blobset);
updateConfig(SubFolder.DISCOVERY, deviceConfig.discovery);
localConfigChange(reason);
waitForConfigSync();
}

private void updateConfig(SubFolder subBlock, Object data) {
Expand Down Expand Up @@ -765,11 +767,15 @@ private void untilLoop(Supplier<Boolean> evaluator, String description) {
info(String.format("start %s after %s", waitingCondition, timeSinceStart()));
updateConfig("before " + description);
recordSequence("Wait for " + description);
messageEvaluateLoop(evaluator);
info(String.format("finished %s after %s", waitingCondition, timeSinceStart()));
waitingCondition = "nothing";
}

private void messageEvaluateLoop(Supplier<Boolean> evaluator) {
while (evaluator.get()) {
receiveMessage();
}
info(String.format("finished %s after %s", waitingCondition, timeSinceStart()));
waitingCondition = "nothing";
}

private void recordSequence(String step) {
Expand Down Expand Up @@ -940,17 +946,20 @@ private void handleEventMessage(SubFolder subFolder, Map<String, Object> message
}
}

protected boolean configUpdateComplete() {
private boolean configNotReady() {
Object receivedConfig = receivedUpdates.get("config");
if (!(receivedConfig instanceof Config)) {
trace("no valid received config");
return false;
}
List<String> differences = configDiffEngine.diff(deviceConfig,
sanitizeConfig((Config) receivedConfig));
if (traceLogLevel() && !differences.isEmpty()) {
boolean configNotReady = !differences.isEmpty();
trace("testing valid received config " + configNotReady);
if (traceLogLevel() && configNotReady) {
trace("\n+- " + Joiner.on("\n+- ").join(differences));
}
return differences.isEmpty();
return configNotReady;
}

protected void trace(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,32 @@ public void endpoint_config_connection_success_reset() {
deviceConfig.system.mode = SystemMode.RESTART;
updateConfig();

untilTrue("deviceState.system.mode == INITIAL", () -> {
return deviceState.system.mode.equals(SystemMode.INITIAL); } );

info("================1 previous last_config = " + last_config);
info("================1 current last_config = " + deviceState.system.last_config);
deviceConfig.system.mode = SystemMode.ACTIVE;
updateConfig();

untilTrue("deviceState.system.mode == ACTIVE", () -> {
return deviceState.system.mode.equals(SystemMode.ACTIVE); } );

info("================1 previous last_config = " + getTimestamp(last_config));
info("================1 current last_config = " + getTimestamp(deviceState.system.last_config));

untilTrue("last_config is newer than previous last_config", () -> deviceState.system.last_config.after(last_config));
untilTrue("last_config is newer than previous last_config", () -> {
info("============ waiting for " +
"current last_config " + getTimestamp(deviceState.system.last_config) + " to be after " +
"previous last_config " + getTimestamp(last_config));
return deviceState.system.last_config.after(last_config);
});

info("================2 previous last_config = " + last_config);
info("================2 current last_config = " + deviceState.system.last_config);
info("================2 previous last_config = " + getTimestamp(last_config));
info("================2 current last_config = " + getTimestamp(deviceState.system.last_config));

untilTrue("last_start is newer than previous last_start (" + last_start + ")", () -> {
untilTrue("last_start is newer than previous last_start " + getTimestamp(last_start), () -> {
info("============ waiting for " +
"current last_start (" + deviceConfig.system.last_start + ") to be after " +
"previous last_start (" + last_start + ")") ;
"current last_start " + getTimestamp(deviceState.system.last_start) + " to be after " +
"previous last_start " + getTimestamp(last_start));
return deviceConfig.system.last_start.after(last_start);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void device_config_acked() {
public void broken_config() {
deviceConfig.system.min_loglevel = Level.DEBUG.value();
untilFalse("no interesting status", this::hasInterestingStatus);
untilTrue("clean config/state synced", this::configUpdateComplete);
syncConfig();
Date stableConfig = deviceConfig.timestamp;
info("initial stable_config " + getTimestamp(stableConfig));
untilTrue("state synchronized", () -> dateEquals(stableConfig, deviceState.system.last_config));
Expand Down

0 comments on commit af46c03

Please sign in to comment.