You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2010/04/21 12:32:50 UTC

[jira] Created: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Broken logic for avoiding testing across midnight in TimestampArithTest
-----------------------------------------------------------------------

                 Key: DERBY-4624
                 URL: https://issues.apache.org/jira/browse/DERBY-4624
             Project: Derby
          Issue Type: Bug
          Components: Test
    Affects Versions: 10.6.0.0
            Reporter: Knut Anders Hatlen
            Priority: Minor


TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:

				/*
				 * Make sure that we are not so close to midnight that TODAY
				 * might be yesterday before we are finished using it.
				 */
				while (calendar.get(Calendar.HOUR) == 23
						&& calendar.get(Calendar.MINUTE) >= 58) {
					try {
						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
					} catch (InterruptedException ie) {
						// ignore it
					}
				}

There are at least three problems with this code:

1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.

2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.

3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4624:
--------------------------------------

            Assignee: Knut Anders Hatlen
    Issue & fix info: [Patch Available]

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: remove_calendar.diff
>
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Dag H. Wanvik (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12867686#action_12867686 ] 

Dag H. Wanvik commented on DERBY-4624:
--------------------------------------

2): wouldn't it just loop forever (since no new time instant is instantiated)?

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4624:
--------------------------------------

    Attachment: remove_calendar.diff

The Calendar object is actually only used to initialize some unused fields, so I think removing it along with the dead code is the simplest and best resolution to this issue. The attached patch removes the Calendar object, the broken midnight check that uses the Calendar, and the unused fields ONE_BILLION, TODAY, TOMORROW, YEAR_FROM_TOMORROW, YEAR_FROM_TODAY, YESTERDAY and WEEK_FROM_TODAY, as well as the method isoFormatDate() that's only used to initialize the unused fields.

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: remove_calendar.diff
>
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Lily Wei (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12867995#action_12867995 ] 

Lily Wei commented on DERBY-4624:
---------------------------------

Will it be okay if we kind of guess the range the test will run and just check the time frame in that range? Will that be a valid test to know most of the validation is accurate?

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12868638#action_12868638 ] 

Knut Anders Hatlen commented on DERBY-4624:
-------------------------------------------

Possibly... But when looking at the test again, I don't really see why this code is needed. We get the Calendar object once and do arithmetic on it, but we never use the current time to verify the values. So I don't see how crossing midnight while running the test will cause any harm.

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12867704#action_12867704 ] 

Knut Anders Hatlen commented on DERBY-4624:
-------------------------------------------

Good point. I've never seen this test fail because it runs across midnight, so perhaps we should just remove the code rather than trying to fix it?

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (DERBY-4624) Broken logic for avoiding testing across midnight in TimestampArithTest

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen closed DERBY-4624.
-------------------------------------

    Issue & fix info:   (was: [Patch Available])
       Fix Version/s: 10.7.0.0
          Resolution: Fixed

Committed revision 946079.

> Broken logic for avoiding testing across midnight in TimestampArithTest
> -----------------------------------------------------------------------
>
>                 Key: DERBY-4624
>                 URL: https://issues.apache.org/jira/browse/DERBY-4624
>             Project: Derby
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 10.6.1.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>             Fix For: 10.7.0.0
>
>         Attachments: remove_calendar.diff
>
>
> TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:
> 				/*
> 				 * Make sure that we are not so close to midnight that TODAY
> 				 * might be yesterday before we are finished using it.
> 				 */
> 				while (calendar.get(Calendar.HOUR) == 23
> 						&& calendar.get(Calendar.MINUTE) >= 58) {
> 					try {
> 						Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000);
> 					} catch (InterruptedException ie) {
> 						// ignore it
> 					}
> 				}
> There are at least three problems with this code:
> 1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.
> 2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.
> 3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.