gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_timeout_test.go (about)

     1  // Code generated by gen_tests.py and process_polyglot.py.
     2  // Do not edit this file directly.
     3  // The template for this file is located at:
     4  // ../template.go.tpl
     5  package reql_tests
     6  
     7  import (
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/stretchr/testify/suite"
    12  	r "gopkg.in/rethinkdb/rethinkdb-go.v6"
    13  	"gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare"
    14  )
    15  
    16  // Tests timeouts.
    17  func TestTimeoutSuite(t *testing.T) {
    18  	suite.Run(t, new(TimeoutSuite))
    19  }
    20  
    21  type TimeoutSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *TimeoutSuite) SetupTest() {
    28  	suite.T().Log("Setting up TimeoutSuite")
    29  	// Use imports to prevent errors
    30  	_ = time.Time{}
    31  	_ = compare.AnythingIsFine
    32  
    33  	session, err := r.Connect(r.ConnectOpts{
    34  		Address: url,
    35  	})
    36  	suite.Require().NoError(err, "Error returned when connecting to server")
    37  	suite.session = session
    38  
    39  	r.DBDrop("test").Exec(suite.session)
    40  	err = r.DBCreate("test").Exec(suite.session)
    41  	suite.Require().NoError(err)
    42  	err = r.DB("test").Wait().Exec(suite.session)
    43  	suite.Require().NoError(err)
    44  
    45  }
    46  
    47  func (suite *TimeoutSuite) TearDownSuite() {
    48  	suite.T().Log("Tearing down TimeoutSuite")
    49  
    50  	if suite.session != nil {
    51  		r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
    52  		r.DBDrop("test").Exec(suite.session)
    53  
    54  		suite.session.Close()
    55  	}
    56  }
    57  
    58  func (suite *TimeoutSuite) TestCases() {
    59  	suite.T().Log("Running TimeoutSuite: Tests timeouts.")
    60  
    61  	{
    62  		// timeout.yaml line #5
    63  		/* err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 5.000 seconds.", [0]) */
    64  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 5.000 seconds.")
    65  		/* r.js('while(true) {}') */
    66  
    67  		suite.T().Log("About to run line #5: r.JS('while(true) {}')")
    68  
    69  		runAndAssert(suite.Suite, expected_, r.JS("while(true) {}"), suite.session, r.RunOpts{
    70  			GeometryFormat: "raw",
    71  			GroupFormat:    "map",
    72  		})
    73  		suite.T().Log("Finished running line #5")
    74  	}
    75  
    76  	{
    77  		// timeout.yaml line #8
    78  		/* err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 1.300 seconds.", [0]) */
    79  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 1.300 seconds.")
    80  		/* r.js('while(true) {}', timeout=1.3) */
    81  
    82  		suite.T().Log("About to run line #8: r.JS('while(true) {}').OptArgs(r.JSOpts{Timeout: 1.3, })")
    83  
    84  		runAndAssert(suite.Suite, expected_, r.JS("while(true) {}").OptArgs(r.JSOpts{Timeout: 1.3}), suite.session, r.RunOpts{
    85  			GeometryFormat: "raw",
    86  			GroupFormat:    "map",
    87  		})
    88  		suite.T().Log("Finished running line #8")
    89  	}
    90  
    91  	{
    92  		// timeout.yaml line #13
    93  		/* err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 8.000 seconds.", [0]) */
    94  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `while(true) {}` timed out after 8.000 seconds.")
    95  		/* r.js('while(true) {}', timeout=8) */
    96  
    97  		suite.T().Log("About to run line #13: r.JS('while(true) {}').OptArgs(r.JSOpts{Timeout: 8, })")
    98  
    99  		runAndAssert(suite.Suite, expected_, r.JS("while(true) {}").OptArgs(r.JSOpts{Timeout: 8}), suite.session, r.RunOpts{
   100  			GeometryFormat: "raw",
   101  			GroupFormat:    "map",
   102  		})
   103  		suite.T().Log("Finished running line #13")
   104  	}
   105  
   106  	{
   107  		// timeout.yaml line #18
   108  		/* err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 5.000 seconds.", [0]) */
   109  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 5.000 seconds.")
   110  		/* r.expr('foo').do(r.js('(function(x) { while(true) {} })')) */
   111  
   112  		suite.T().Log("About to run line #18: r.Expr('foo').Do(r.JS('(function(x) { while(true) {} })'))")
   113  
   114  		runAndAssert(suite.Suite, expected_, r.Expr("foo").Do(r.JS("(function(x) { while(true) {} })")), suite.session, r.RunOpts{
   115  			GeometryFormat: "raw",
   116  			GroupFormat:    "map",
   117  		})
   118  		suite.T().Log("Finished running line #18")
   119  	}
   120  
   121  	{
   122  		// timeout.yaml line #21
   123  		/* err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 1.300 seconds.", [0]) */
   124  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 1.300 seconds.")
   125  		/* r.expr('foo').do(r.js('(function(x) { while(true) {} })', timeout=1.3)) */
   126  
   127  		suite.T().Log("About to run line #21: r.Expr('foo').Do(r.JS('(function(x) { while(true) {} })').OptArgs(r.JSOpts{Timeout: 1.3, }))")
   128  
   129  		runAndAssert(suite.Suite, expected_, r.Expr("foo").Do(r.JS("(function(x) { while(true) {} })").OptArgs(r.JSOpts{Timeout: 1.3})), suite.session, r.RunOpts{
   130  			GeometryFormat: "raw",
   131  			GroupFormat:    "map",
   132  		})
   133  		suite.T().Log("Finished running line #21")
   134  	}
   135  
   136  	{
   137  		// timeout.yaml line #26
   138  		/* err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 8.000 seconds.", [0]) */
   139  		var expected_ Err = err("ReqlQueryLogicError", "JavaScript query `(function(x) { while(true) {} })` timed out after 8.000 seconds.")
   140  		/* r.expr('foo').do(r.js('(function(x) { while(true) {} })', timeout=8)) */
   141  
   142  		suite.T().Log("About to run line #26: r.Expr('foo').Do(r.JS('(function(x) { while(true) {} })').OptArgs(r.JSOpts{Timeout: 8, }))")
   143  
   144  		runAndAssert(suite.Suite, expected_, r.Expr("foo").Do(r.JS("(function(x) { while(true) {} })").OptArgs(r.JSOpts{Timeout: 8})), suite.session, r.RunOpts{
   145  			GeometryFormat: "raw",
   146  			GroupFormat:    "map",
   147  		})
   148  		suite.T().Log("Finished running line #26")
   149  	}
   150  
   151  	{
   152  		// timeout.yaml line #32
   153  		/* err("ReqlNonExistenceError", "Error in HTTP GET of `httpbin.org/delay/10`:" + " timed out after 0.800 seconds.", []) */
   154  		var expected_ Err = err("ReqlNonExistenceError", "Error in HTTP GET of `httpbin.org/delay/10`:"+" timed out after 0.800 seconds.")
   155  		/* r.http('httpbin.org/delay/10', timeout=0.8) */
   156  
   157  		suite.T().Log("About to run line #32: r.HTTP('httpbin.org/delay/10').OptArgs(r.HTTPOpts{Timeout: 0.8, })")
   158  
   159  		runAndAssert(suite.Suite, expected_, r.HTTP("httpbin.org/delay/10").OptArgs(r.HTTPOpts{Timeout: 0.8}), suite.session, r.RunOpts{
   160  			GeometryFormat: "raw",
   161  			GroupFormat:    "map",
   162  		})
   163  		suite.T().Log("Finished running line #32")
   164  	}
   165  
   166  	{
   167  		// timeout.yaml line #36
   168  		/* err("ReqlNonExistenceError", "Error in HTTP PUT of `httpbin.org/delay/10`:" + " timed out after 0.000 seconds.", []) */
   169  		var expected_ Err = err("ReqlNonExistenceError", "Error in HTTP PUT of `httpbin.org/delay/10`:"+" timed out after 0.000 seconds.")
   170  		/* r.http('httpbin.org/delay/10', method='PUT', timeout=0.0) */
   171  
   172  		suite.T().Log("About to run line #36: r.HTTP('httpbin.org/delay/10').OptArgs(r.HTTPOpts{Method: 'PUT', Timeout: 0.0, })")
   173  
   174  		runAndAssert(suite.Suite, expected_, r.HTTP("httpbin.org/delay/10").OptArgs(r.HTTPOpts{Method: "PUT", Timeout: 0.0}), suite.session, r.RunOpts{
   175  			GeometryFormat: "raw",
   176  			GroupFormat:    "map",
   177  		})
   178  		suite.T().Log("Finished running line #36")
   179  	}
   180  }