testify icon indicating copy to clipboard operation
testify copied to clipboard

`suite.Require` deadlock

Open vitalyisaev2 opened this issue 2 years ago • 1 comments

If require object hasn't been initialized before calling suite.Require method, it will be created on the base of *testing.T returned from suite.T() (code):

// Require returns a require context for suite.
func (suite *Suite) Require() *require.Assertions {
	suite.mu.Lock()
	defer suite.mu.Unlock()
	if suite.require == nil {
		suite.require = require.New(suite.T())
	}
	return suite.require
}

This will result in a deadlock because suite.T() wants to acquire the lock that has been already acquired:

// T retrieves the current *testing.T context.
func (suite *Suite) T() *testing.T {
	suite.mu.RLock()
	defer suite.mu.RUnlock()
	return suite.t
}

vitalyisaev2 avatar Dec 27 '23 10:12 vitalyisaev2

Thanks for reporting this @vitalyisaev2!

I've put up a PR for fixing this. If you have any thoughts about the approach, please comment on #1535

arjunmahishi avatar Feb 16 '24 19:02 arjunmahishi