Testing Framework Bug

Visto 56 veces
Saltar al primer mensaje no leído

Roshan

no leída,
5 ago 2011, 12:40:285/8/11
a play-framework
I have fully isolated this problem to a very simple play app
I think it has to do with some DB caching, but I can't figure it out

BasicTest.java
==========

import org.junit.*;
import play.test.*;
import play.Logger;
import models.*;
import play.mvc.Http.*;


public class BasicTest extends FunctionalTest {

@Before public void setUp() {
Fixtures.deleteDatabase();
Fixtures.loadModels("data.yml");
Logger.debug("countFromSetup=%s",User.count());

}

@Test
public void test() {
Response response= GET("/");
Logger.debug("countFromTest=%s",User.count());
assertIsOk(response);

}

}

Uncommented Configs
================

%prod.application.mode=prod
%test.application.mode=dev
%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.db=mysql:root:xxx@t_db
%test.jpa.ddl=create
%test.mail.smtp=mock
application.mode=dev
application.name=test
application.secret=jXKw4HabjhaNvosxgzq39to9BJECtOr39EXrEabsQAZKi7YoWAwQWo3BBFUOQnJw
attachments.path=data/attachments
date.format=yyyy-MM-dd
db=mysql:root:xxx@db
mail.smtp=mock

Application.java
============

package controllers;

import play.*;
import play.mvc.*;
import models.*;

public class Application extends Controller {

public static void index() {
Logger.debug("countFromIndex=%s",User.count());
render();
}

}

>play test
Output of log after running the BasicTest http://localhost:9000/@tests
==================================================
11:54:59,008 DEBUG ~ countFromSetup=1
11:54:59,021 DEBUG ~ countFromIndex=0
11:54:59,034 DEBUG ~ countFromTest=1

point to browser=> http://localhost:9000
12:25:59,781 DEBUG ~ countFromIndex=1

What happened to the record during?
Response response= GET("/");

This 'bug' almost makes my test cases useless

Julien Tournay

no leída,
6 ago 2011, 7:39:136/8/11
a play-fr...@googlegroups.com
Hi,

I've read a while ago that Mysql's "count" function is cached, and the result does not always reflect the real number of rows in a table. I don't know if it's still the case but it could be the source of your problem.

jto.


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
Real Programmers don't need comments-- the code is obvious.

T.J. Crowder

no leída,
6 ago 2011, 8:47:036/8/11
a play-framework
Hi,

On Aug 6, 12:39 pm, Julien Tournay <boudhe...@gmail.com> wrote:
> Hi,
>
> I've read a while ago that Mysql's "count" function is cached, and the
> result does not always reflect the real number of rows in a table. I don't
> know if it's still the case but it could be the source of your problem.
>
> jto.

I've never had MySQL's `count` not return the real number in an
uncorrupted table. It's true that the total number of rows in the
table is (unsurprisingly) stored information in at least the MyISAM
storage engine and presumably others, and MySQL is smart enough to use
that stored number if you use `count(*)` (whereas `count(colname)`
will go to an index or table scan if the column is nullable, because
of possible NULLs), but I'm not aware of any reports that it's wrong
(again, barring a corrupted table). Do you have a reference for that?
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

GrailsDeveloper

no leída,
6 ago 2011, 10:52:066/8/11
a play-framework
Looks like a transaction problem to me. Server and Test running in
different transactions, so you must make sure that a commit is
processed.

Niels

Roshan

no leída,
8 ago 2011, 11:22:258/8/11
a play-framework

On Aug 6, 10:52 am, GrailsDeveloper <opensourc...@googlemail.com>
wrote:
> Looks like a transaction problem to me. Server and Test running in
> different transactions, so you must make sure that a commit is
> processed.
>
> Niels
>

Even if it is a commit issue, it is a framework error.
I'm not handling any transactions and
Fixtures.deleteDatabase();
Fixtures.loadModels("data.yml");

should take care of all those issues...

GrailsDeveloper

no leída,
8 ago 2011, 15:07:298/8/11
a play-framework
Hi,
I have a look to the code: The framework call EntityManager.clear().
So normally Hibernate should save this, but I'm unsure how fast this
will be done. Perhaps it would be better if an explicit commit would
be done. Please raise an issue with a zipped sample app.

Niels

GrailsDeveloper

no leída,
8 ago 2011, 15:28:308/8/11
a play-framework
Hi

> > should take care of all those issues...
>
> I have a look to the code: The framework call EntityManager.clear().
> So normally Hibernate should save this, but I'm unsure how fast this
> will be done. Perhaps it would be better if an explicit commit would
> be done. Please raise an issue with a zipped sample app.

or better with a test which fails. You can let the controller return
the read number.

Thanks
Niels

Roshan

no leída,
8 ago 2011, 23:46:078/8/11
a play-framework


On Aug 8, 3:28 pm, GrailsDeveloper <opensourc...@googlemail.com>
wrote:
Thanks, Is there a standard way/place to upload .zip files?

Another piece of information

The Test case runs perfectly fine with
%test.db=mem

but fails with
%test.db=mysql:root:xxx@t_db

GrailsDeveloper

no leída,
9 ago 2011, 2:27:449/8/11
a play-framework
Hi
I send you a patched jar. Can you try if it works? I guess it's a
timing problem. So it's possible that it works fine on other machines.
You can easily attach files at http://play.lighthouseapp.com/projects/57987-play-framework/overview

Niels
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos