Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Williams2016-08-26 18:01:57 +0000
committerDavid Williams2016-08-26 18:01:57 +0000
commit464ec9455474ab0caa4829b4e90f730f7e3784f7 (patch)
tree6d9ce5a0423cbfcfe3b2796cb3abc6618dc20264 /production/buildScriptsUnitTests
parente80867631ae20f4b4a6a32fcfd386f5fc29fdda9 (diff)
downloadeclipse.platform.releng.aggregator-464ec9455474ab0caa4829b4e90f730f7e3784f7.tar.gz
eclipse.platform.releng.aggregator-464ec9455474ab0caa4829b4e90f730f7e3784f7.tar.xz
eclipse.platform.releng.aggregator-464ec9455474ab0caa4829b4e90f730f7e3784f7.zip
Bug 500233 - Build IDs 1 minute too early
Improved fix truncating epoch seconds to nearest 5 minutes.
Diffstat (limited to 'production/buildScriptsUnitTests')
-rwxr-xr-xproduction/buildScriptsUnitTests/timeTruncatedToFiveMinutes.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/production/buildScriptsUnitTests/timeTruncatedToFiveMinutes.sh b/production/buildScriptsUnitTests/timeTruncatedToFiveMinutes.sh
new file mode 100755
index 000000000..05092b7ed
--- /dev/null
+++ b/production/buildScriptsUnitTests/timeTruncatedToFiveMinutes.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+# small test utility to verify that "time truncation" works as expected.
+# Such as, confirms there is no "off by one" errors at our choosen interval of 5 minutes.
+
+# Have not tried running over "midnight", but should not impact results.
+# Have also not tested if "system time" changes in the middle of things. That might impact accuracy,
+# but should still be aligned on interval since we only "get" the time in one statement.
+
+# run for one hour. Can vary as desired, but does interact with the "sleep interval".
+max_loops=$(( 3600 * 1))
+count=0
+# debug=true produces more detailed ouput
+#debug=true
+
+while [[ $count -lt $max_loops ]]
+do
+ # use a "empty statement" (:), to do increment only, without result being interpreted as a command.
+ : $(( count++))
+
+ # %s is seconds since epoch. That is, seconds since 1970-01-01 00:00:00 UTC
+ RAWDATE=$( date +%s )
+
+ # Find "remainder" after dividing by 5 minutes (300 seconds)
+
+ # Doesn't seem to matter, for bash aritmetic, if variables in equation have '$' or not.
+ # Confirmed in http://wiki.bash-hackers.org/scripting/newbie_traps
+ # And, better, in the official Bash Reference Manual:
+ # https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html#Shell-Arithmetic
+ remainder=$(( RAWDATE % 300 ))
+ RAWDATE_TRUNC=$(( RAWDATE - remainder ))
+ TIMESTAMP_SECONDS=$( date +%Y%m%d-%H%M%S --date='@'$RAWDATE )
+ TIMESTAMP_MIN=$( date +%Y%m%d-%H%M --date='@'$RAWDATE )
+ TIMESTAMP=$( date +%Y%m%d-%H%M --date='@'$RAWDATE_TRUNC )
+
+ # print results only on "5 minute" intervals.
+ # This can be modify in many ways depending on degree of output desired.
+ if [[ $remainder == 0 ]]
+ then
+ printf "\n\t================"
+ #fi
+ if [[ "$debug" == "true" ]]
+ then
+ printf "\n\t%-45s\t%15s" "[DEBUG] loop count:" "$count"
+ printf "\n\t%-45s\t%15s" "[DEBUG] Epoch seconds:" "$RAWDATE"
+ printf "\n\t%-45s\t%15s" "[DEBUG] Truncated epoch seconds:" "$RAWDATE_TRUNC"
+ printf "\n\t%-45s\t%15s" "[DEBUG] Remainder: " "$remainder"
+ fi
+ printf "\n\t%-45s" "Timestamps:"
+ printf "\n\t\t%-45s\t\t%s" "with seconds:" "$TIMESTAMP_SECONDS"
+ printf "\n\t\t%-45s\t\t%s" "to previous minute (as in current BUILD_ID):" "$TIMESTAMP_MIN"
+ printf "\n\t\t%-45s\t%s\n" "to previous 5 minutes (as proposed in bug 500233):" "$TIMESTAMP"
+ fi
+
+ # We sleep for exactly one second, currently, though another
+ # test routine could wait and start on an exact minute, and then sleep for one minute.
+ sleep 1
+
+done
+

Back to the top