MCPcopy
hub / github.com/rubenv/sql-migrate / TestContextTimeout

Method TestContextTimeout

migrate_test.go:780–814  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

778}
779
780func (s *SqliteMigrateSuite) TestContextTimeout(c *C) {
781 // This statement will run for a long time: 1,000,000 iterations of the fibonacci sequence
782 fibonacciLoopStmt := `WITH RECURSIVE
783 fibo (curr, next)
784 AS
785 ( SELECT 1,1
786 UNION ALL
787 SELECT next, curr+next FROM fibo
788 LIMIT 1000000 )
789 SELECT group_concat(curr) FROM fibo;
790 `
791 migrations := &MemoryMigrationSource{
792 Migrations: []*Migration{
793 sqliteMigrations[0],
794 sqliteMigrations[1],
795 {
796 Id: "125",
797 Up: []string{fibonacciLoopStmt},
798 Down: []string{}, // Not important here
799 },
800 {
801 Id: "125",
802 Up: []string{"INSERT INTO people (id, first_name) VALUES (1, 'Test')", "SELECT fail"},
803 Down: []string{}, // Not important here
804 },
805 },
806 }
807
808 // Should never run the insert
809 ctx, cancelFunc := context.WithTimeout(context.Background(), 10*time.Millisecond)
810 defer cancelFunc()
811 n, err := ExecContext(ctx, s.Db, "sqlite3", migrations, Up)
812 c.Assert(err, Not(IsNil))
813 c.Assert(n, Equals, 2)
814}
815
816//go:embed test-migrations/*
817var testEmbedFS embed.FS

Callers

nothing calls this directly

Calls 1

ExecContextFunction · 0.85

Tested by

no test coverage detected