Switch to Daemon user (TRUNK-5189)

Hi Devs
Am working on TRUNK-5189 and already came up with an initial commit. I expected this to add the required feature correctly but its portraying a stubborn behavior. As you can see, the CI build failed :frowning: .

The weird behavior
What confuses me is , when I run all tests in AlertServiceTest class in a single run only one passes but when I run single tests ie commenting out other tests, they all run successfully :slight_smile: for example `

public class AlertServiceTest extends BaseContextSensitiveTest {
/*
@Test
public void notifySuperUsers_shouldAddAnAlertWithMessageOfLengthEqualsTextMaxLength(){ 
}
@Test
public void notifySuperUsers_shouldAddAnAlertWithMessageTextIfCauseIsNull() {
}
*/

@Test
public void notifySuperUsers_shouldAddAnAlertToTheDatabase() {	
}

All tests run successfully just in case I run it one by one like the demo above. What could cause such a behavior ? Could the scheduled threads be colliding in any way. Please tell what could have caused this :frowning:
cc: @mksd , @dkayiwa,@darius etc

It could definitely be that this ‘daemon thread user’ behaves differently. Is everything ok if you use this user instead? So by just changing

User user = Daemon.getDaemonThreadUser();
alert.setCreator(user);

with this:

User user = Context.getUserService().getUser(501);
alert.setCreator(user);

That’s just for the sake of troubleshooting.

Thanks for the interest show :slight_smile: but it still fails full log.
I think this has no issue with the User type regardless of whether its Daemon or not. But I think Daemon threads must be cause of the failure if Otherwise, then please guys look into this. cc @mksd ,@dkayiwa , @darius @bwolfe

Hi,
I was still troubleshooting what could be the cause. What I realized was the Unit tests don’t rollBack() after each transaction. So committed data remains in the in-memory database and affect execution of subsequent tests. Adding this solved the issue :slight_smile:

@After
public void makeSureCleanDatabase() {
	 deleteAllData();
}

But could this be the recommended solution? :roll_eyes:
cc @mksd,@dkayiwa,@darius etc.

1 Like

Good troubleshooting @samuel34! A bit nitpicky but I don’t like so much the naming so much. Perhaps something like this?

@After
public void tearDown() {
  // <explain here why you need to do the below>
  deleteAllData();
}

I’m not sure why this is happening but its like the Daemon thread really commits data in the inMemory database and doesn’t roll back. This affects the subsequent tests and endup failing. I added that to explicitly rollback. Now what the question is, why isn’t it rolling back automatically ass expected after every unit Test :face_with_thermometer: