-
Notifications
You must be signed in to change notification settings - Fork 48
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
Increase test stability and cleanup some logging/debug #478
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
36e12b6
Adjust crontab
grafnu 1c12796
Fix some logging things
grafnu 0b10a5d
Add safe sleep delay
grafnu 0d775b9
Make discovery generation more exact
grafnu f90eb6e
Cleanup discovery
grafnu 2843c76
Add discovery event logging
grafnu 77c0bc5
Proper filter event
grafnu 9ab5eed
Variable rename
grafnu e9a400e
Remove debugging
grafnu 46f7c1b
REgistrar debugging
grafnu d44da52
Remove debugging
grafnu 54bc403
Increase sleep delay to be extra sure
grafnu 4674ce9
Revert cron change
grafnu 80fed3f
Adding TODO
grafnu daba570
Use named constant
grafnu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static com.google.daq.mqtt.sequencer.semantic.SemanticValue.actualize; | ||
import static com.google.daq.mqtt.util.JsonUtil.getTimestamp; | ||
import static com.google.daq.mqtt.util.JsonUtil.safeSleep; | ||
import static com.google.daq.mqtt.util.JsonUtil.stringify; | ||
import static java.util.Optional.ofNullable; | ||
|
||
|
@@ -38,7 +39,6 @@ | |
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.io.FileUtils; | ||
|
@@ -81,7 +81,6 @@ public abstract class SequenceBase { | |
public static final String SYSTEM_EVENT_MESSAGE_BASE = "event_system"; | ||
public static final int CONFIG_UPDATE_DELAY_MS = 2000; | ||
public static final int NORM_TIMEOUT_MS = 120 * 1000; | ||
public static final String LOCAL_CONFIG = "local_config"; | ||
private static final String EMPTY_MESSAGE = "{}"; | ||
private static final String CLOUD_IOT_CONFIG_FILE = "cloud_iot_config.json"; | ||
private static final String RESULT_LOG_FILE = "RESULT.log"; | ||
|
@@ -103,10 +102,12 @@ public abstract class SequenceBase { | |
private static final Map<String, AtomicInteger> UPDATE_COUNTS = new HashMap<>(); | ||
private static final long LOG_CLEAR_TIME_MS = 1000; | ||
private static final String LOCAL_PREFIX = "local_"; | ||
private static final String LOCAL_CONFIG_UPDATE = LOCAL_PREFIX + "update"; | ||
private static final String SEQUENCER_LOG = "sequencer.log"; | ||
private static final String SYSTEM_LOG = "system.log"; | ||
private static final String SEQUENCE_MD = "sequence.md"; | ||
private static final String CONFIG_NONCE_KEY = "debug_config_nonce"; | ||
private static final long CLEAN_START_DELAY_MS = 20 * 1000; | ||
protected static Metadata deviceMetadata; | ||
protected static String projectId; | ||
protected static String deviceId; | ||
|
@@ -392,6 +393,9 @@ private Config readGeneratedConfig() { | |
*/ | ||
@Before | ||
public void setUp() { | ||
// Old messages can sometimes take a while to clear out, so need some delay for stability. | ||
safeSleep(CLEAN_START_DELAY_MS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a TODO to minimize this time or change the strategy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
deviceState = new State(); | ||
configAcked = false; | ||
receivedState.clear(); | ||
|
@@ -502,7 +506,7 @@ private void recordRawMessage(Map<String, Object> message, String messageBase) { | |
try { | ||
JsonUtil.OBJECT_MAPPER.writeValue(messageFile, message); | ||
boolean traceMessage = | ||
traceLogLevel() || (debugLogLevel() && messageBase.equals(LOCAL_CONFIG)); | ||
traceLogLevel() || (debugLogLevel() && messageBase.equals(LOCAL_CONFIG_UPDATE)); | ||
String postfix = | ||
traceMessage ? (message == null ? ": (null)" : ":\n" + stringify(message)) : ""; | ||
if (messageBase.equals(SYSTEM_EVENT_MESSAGE_BASE)) { | ||
|
@@ -629,17 +633,12 @@ private void updateConfig(SubFolder subBlock, Object data) { | |
@SuppressWarnings("unchecked") | ||
private Object augmentConfigTrace(Object data) { | ||
try { | ||
if (data == null) { | ||
return null; | ||
} | ||
if (traceLogLevel()) { | ||
String messageData = stringify(data); | ||
Map<String, Long> map = JsonUtil.OBJECT_MAPPER.readValue(messageData, Map.class); | ||
map.put(CONFIG_NONCE_KEY, System.currentTimeMillis()); | ||
return map; | ||
} else { | ||
if (data == null || !traceLogLevel()) { | ||
return data; | ||
} | ||
Map<String, Object> map = JsonUtil.convertTo(Map.class, data); | ||
map.put(CONFIG_NONCE_KEY, System.currentTimeMillis()); | ||
return map; | ||
} catch (Exception e) { | ||
throw new RuntimeException("While augmenting data message", e); | ||
} | ||
|
@@ -650,7 +649,7 @@ private void localConfigChange(String reason) { | |
String suffix = reason == null ? "" : (" " + reason); | ||
String header = String.format("Update config%s:", suffix); | ||
debug(header + " " + getTimestamp(deviceConfig.timestamp)); | ||
recordRawMessage(deviceConfig, LOCAL_PREFIX + "config"); | ||
recordRawMessage(deviceConfig, LOCAL_CONFIG_UPDATE); | ||
List<String> configUpdates = configDiffEngine.computeChanges(deviceConfig); | ||
if (configUpdates.isEmpty()) { | ||
return; | ||
|
@@ -676,27 +675,6 @@ private AugmentedSystemConfig augmentConfig(SystemConfig system) { | |
} | ||
} | ||
|
||
private <T> boolean updateState(SubFolder subFolder, SubFolder expected, Class<T> target, | ||
Map<String, Object> message, Consumer<T> handler) { | ||
try { | ||
if (!expected.equals(subFolder)) { | ||
return false; | ||
} | ||
message.remove("timestamp"); | ||
message.remove("version"); | ||
String messageString = stringify(message); | ||
boolean updated = !messageString.equals(receivedState.get(subFolder)); | ||
if (updated) { | ||
debug(String.format("updating %s state", subFolder)); | ||
T state = JsonUtil.OBJECT_MAPPER.readValue(messageString, target); | ||
handler.accept(state); | ||
} | ||
return updated; | ||
} catch (Exception e) { | ||
throw new RuntimeException("While converting state type " + subFolder, e); | ||
} | ||
} | ||
|
||
protected boolean validSerialNo() { | ||
String deviceSerial = deviceState == null ? null | ||
: deviceState.system == null ? null : deviceState.system.serial_no; | ||
|
@@ -745,7 +723,7 @@ protected void checkThat(String description, Supplier<Boolean> condition) { | |
|
||
protected List<Map<String, Object>> clearLogs() { | ||
info("clearing system logs..."); | ||
JsonUtil.safeSleep(LOG_CLEAR_TIME_MS); | ||
safeSleep(LOG_CLEAR_TIME_MS); | ||
lastLog = null; | ||
return receivedEvents.remove(SubFolder.SYSTEM); | ||
} | ||
|
@@ -905,7 +883,7 @@ private synchronized void handleReflectorMessage(String subFolderRaw, | |
} | ||
Config config = (Config) converted; | ||
updateDeviceConfig(config); | ||
info("Updated config with timestamp " + JsonUtil.getTimestamp(config.timestamp)); | ||
debug("Updated config with timestamp " + JsonUtil.getTimestamp(config.timestamp)); | ||
debug(String.format("Updated config #%03d:\n%s", updateCount, | ||
stringify(converted))); | ||
} else if (converted instanceof AugmentedState) { | ||
|
@@ -914,7 +892,7 @@ private synchronized void handleReflectorMessage(String subFolderRaw, | |
deviceState = (State) converted; | ||
updateConfigAcked((AugmentedState) converted); | ||
validSerialNo(); | ||
info("Updated state has last_config " + JsonUtil.getTimestamp( | ||
debug("Updated state has last_config " + JsonUtil.getTimestamp( | ||
deviceState.system.last_config)); | ||
} else { | ||
error("Unknown update type " + converted.getClass().getSimpleName()); | ||
|
@@ -970,7 +948,7 @@ protected boolean configUpdateComplete() { | |
List<String> differences = configDiffEngine.diff(deviceConfig, | ||
sanitizeConfig((Config) receivedConfig)); | ||
if (traceLogLevel() && !differences.isEmpty()) { | ||
trace("+- " + Joiner.on("\n+- ").join(differences)); | ||
trace("\n+- " + Joiner.on("\n+- ").join(differences)); | ||
} | ||
return differences.isEmpty(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be MessageUpgrader.METADATA_SCHEMA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.