Skip to content

Can I use the same pgxmock.NewPool() across tests? #214

Answered by pashagolub
aravindhp asked this question in Q&A
Discussion options

You must be logged in to vote

Hello.

Am I following a bad pattern here?

By default pgxmock expects commands to be executed in order. If you run tests in parallel, of course, there is no opportunity to keep that order. It is possible to explicitly ignore the order of the commands:

	mock, _ := NewConn()
	mock.MatchExpectationsInOrder(false)
...
// run your magic

Is it a bad pattern to use one global mock? Not really, sometimes (not that often though) you need to stress your code in parallel and that might be a good idea.

Should I be instantiating a new mock pool for each test?

I prefer to use local mockPool for every test:

  • it's lightweight and doesn't stress the system;
  • it's easier to control expectations and flows;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aravindhp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants