Skip to content

Commit

Permalink
Fixed test case (timing is now non-trivial) (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed May 18, 2021
1 parent 440e2c7 commit 695d3b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ public synchronized void remove(Thermostat ts) {
ts2damper.remove(ts);
}

public synchronized void stateChanged(Thermostat source, ThermostatSignal signal) {
/**
* {@inheritDoc}
*/
public synchronized Future<TransitionStatus> stateChanged(Thermostat source, ThermostatSignal signal) {

ThreadContext.push("signalChanged");

Expand All @@ -146,12 +149,11 @@ public synchronized void stateChanged(Thermostat source, ThermostatSignal signal
logger.info("Demand: " + source.getName() + "=" + signal.demand.sample);
logger.info("ts2signal.size()=" + ts2signal.size());

sync();
return sync();

} finally {
ThreadContext.pop();
}

}

public synchronized void consume(DataSample<UnitSignal> signal) {
Expand Down Expand Up @@ -206,7 +208,7 @@ public synchronized void consume(DataSample<UnitSignal> signal) {
}
}

private void park(boolean async) {
private Future<TransitionStatus> park(boolean async) {

ThreadContext.push("park");

Expand All @@ -224,10 +226,12 @@ private void park(boolean async) {
damperMap.put(d, d.getParkPosition());
}

shuffle(damperMap, async);
Future<TransitionStatus> done = shuffle(damperMap, async);

logger.info("parked");

return done;

} finally {
ThreadContext.pop();
}
Expand Down Expand Up @@ -310,19 +314,19 @@ public synchronized String[] getDamperMap() {
/**
* Recalculate the damper state according to [possibly] changed internal state.
*/
protected final void sync() {
protected final Future<TransitionStatus> sync() {

// VT: NOTE: This assumes compute() is stateless, ideally, it should stay that way.
// If there is ever a need to make it stateful, compute() should be called outside
// of the fork and the map passed to shuffle) within.

if (this.hvacSignal != null && this.hvacSignal.sample.running) {

shuffle(compute(), true);
return shuffle(compute(), true);

} else {

park(true);
return park(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void testBoundaries() {
/**
* Make sure that zero demand from all thermostats doesn't cause NaN sent to dampers.
*/
public void testNaN() {
public void testNaN() throws InterruptedException, ExecutionException {

ThreadContext.push("testNaN");

Expand All @@ -76,7 +77,11 @@ public void testNaN() {
// No calculations are performed unless the HVAC unit signal is present
damperController.consume(new DataSample<UnitSignal>("unit1", "unit1", new UnitSignal(1.0, true, 0), null));

damperController.stateChanged(ts1, new ThermostatSignal(true, false, true, true, new DataSample<Double>("ts1", "ts1", -50.0, null)));
Future<TransitionStatus> done = damperController.stateChanged(ts1, new ThermostatSignal(true, false, true, true, new DataSample<Double>("ts1", "ts1", -50.0, null)));

TransitionStatus status = done.get();

assertTrue(status.isOK());

logger.debug("about to assert");

Expand Down

0 comments on commit 695d3b2

Please sign in to comment.