MCPcopy Index your code
hub / github.com/upper/db / TestExhaustConnectionPool

Method TestExhaustConnectionPool

internal/testsuite/sql_suite.go:1809–1864  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1807}
1808
1809func (s *SQLTestSuite) TestExhaustConnectionPool() {
1810 if s.Adapter() == "ql" {
1811 s.T().Skip("Currently not supported.")
1812 return
1813 }
1814
1815 sess := s.Session()
1816 errRolledBack := errors.New("rolled back")
1817
1818 var wg sync.WaitGroup
1819 for i := 0; i < 100; i++ {
1820 s.T().Logf("Tx %d: Pending", i)
1821
1822 wg.Add(1)
1823 go func(wg *sync.WaitGroup, i int) {
1824 defer wg.Done()
1825
1826 // Requesting a new transaction session.
1827 start := time.Now()
1828 s.T().Logf("Tx: %d: NewTx", i)
1829
1830 expectError := false
1831 if i%2 == 1 {
1832 expectError = true
1833 }
1834
1835 err := sess.Tx(func(tx db.Session) error {
1836 s.T().Logf("Tx %d: OK (time to connect: %v)", i, time.Since(start))
1837 // Let's suppose that we do a bunch of complex stuff and that the
1838 // transaction lasts 3 seconds.
1839 time.Sleep(time.Second * 3)
1840
1841 if expectError {
1842 if _, err := tx.SQL().DeleteFrom("artist").Exec(); err != nil {
1843 return err
1844 }
1845 return errRolledBack
1846 }
1847
1848 var account map[string]interface{}
1849 if err := tx.Collection("artist").Find().One(&account); err != nil {
1850 return err
1851 }
1852 return nil
1853 })
1854 if expectError {
1855 s.Error(err)
1856 s.True(errors.Is(err, errRolledBack))
1857 } else {
1858 s.NoError(err)
1859 }
1860 }(&wg, i)
1861 }
1862
1863 wg.Wait()
1864}
1865
1866func (s *SQLTestSuite) TestCustomType() {

Callers

nothing calls this directly

Calls 13

AdapterMethod · 0.65
SessionMethod · 0.65
NewMethod · 0.65
DoneMethod · 0.65
TxMethod · 0.65
ExecMethod · 0.65
DeleteFromMethod · 0.65
SQLMethod · 0.65
OneMethod · 0.65
FindMethod · 0.65
CollectionMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected