Skip to content
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

Transaction not working in test #67

Open
dsvteam opened this issue Jul 12, 2018 · 4 comments
Open

Transaction not working in test #67

dsvteam opened this issue Jul 12, 2018 · 4 comments

Comments

@dsvteam
Copy link

dsvteam commented Jul 12, 2018

This is my code for DAO testing

        testdata.ResetDB()
	rs := testdata.GetRequestScopeTest()

        // I have to insert this stuff :\
	_, err := testdata.DB.Begin()
	if err != nil {
		panic(err)
	}
        // Then, start a `real` transaction here
	tx, err := testdata.DB.Begin()
	if err != nil {
		panic(err)
	}
	rs.SetTx(tx)
	defer func() {
		if err := rs.Tx().Commit(); err != nil {
			t.Error(err)
		}
	}()

	// My DB operations come here

I'm trying to seed Postgres DB with ozzo-dbx (since I used it too in my main app).
When I write my tests, I began a transaction and start my own DB operations later for DAO testing.
But as you can see from my comment above, I have to insert a dumb transaction begin to make it works, if not I will get this error:

label_test.go:29: pq: relation "prescription_state" does not exist
label_test.go:31: Pre []models.PrescriptionState(nil)
label_test.go:36: Actual 0, expected: 6
label_test.go:22: pq: Could not complete operation in a failed transaction

It's kinda weird for me since everything works fine in my main app but these tests.
Can someone spot any of my mistakes here or is it a potential bug from package?
Thank in advance.

@kPshi
Copy link

kPshi commented Jul 24, 2018

Seems like you do not have all tables and/or relations in the first place. Do you have some SQL level log available?

@akaipham
Copy link

akaipham commented Aug 9, 2018

Hi @kPshi , we've already all tables/ relations in a sql file to be executed. So I don't think its missing in sql file or so.

The problem is when we start a fake Tx then a real Tx, it could execute our SQL file. But when we have only 1 started Tx, it yields the logs above. Kinda wierd

@kPshi
Copy link

kPshi commented Aug 9, 2018

Right, only that error looks like it is raised by the DB server so that something seems to be queried during that first transaction that does not exist.
When you got everything in place already, that missing bit may be due to some inner state of your client. So I was hoping for some insight by seeing what it does on DB side, thus the SQL log.

Anyways: talking about that issue gave me one or two ideas of what to dive into. The logs would be great nevertheless. Setting a logger for ozzo should be enough (see LogFunc).

@kPshi
Copy link

kPshi commented Aug 10, 2018

Failed to reproduce the error. Do you have a minimal buildable example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants