Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test freezes for no apparent reason #36

Closed
onsi opened this issue May 24, 2014 · 1 comment
Closed

Test freezes for no apparent reason #36

onsi opened this issue May 24, 2014 · 1 comment
Assignees

Comments

@onsi
Copy link
Owner

onsi commented May 24, 2014

This was originally over at onsi/ginkgo#71

The following is an extraction of a freezing test. When you run the following, Hello!!! gets printed, but Bye!!! does not because Expect(d.Db).To(BeNil()) freezes for no apparent reason. Go bug?

package test

import (
        "database/sql"
        "fmt"
        "testing"

        . "github.com/onsi/ginkgo"
        . "github.com/onsi/gomega"

        _ "github.com/mattn/go-sqlite3"
)

type Database struct {
        Db *sql.DB
}

func NewSqliteDatabase(dbfile string) (*Database, error) {
        db, err := sql.Open("sqlite3", dbfile)
        if err != nil {
                return nil, err
        }
        return &Database{Db: db}, nil
}

func TestFoo(t *testing.T) {
        RegisterFailHandler(Fail)
        RunSpecs(t, "foo")
}

var _ = Describe("Foo", func() {
        var (
                d *Database
        )

        Describe("NewSqliteDatabase()", func() {
                BeforeEach(func() {
                        d, _ = NewSqliteDatabase("/tmp/test.sqlite3")
                })

                It("opens a sqlite3 database and returns *Database", func() {
                        fmt.Println("Hello!!!")
                        Expect(d.Db).To(BeNil())
                        fmt.Println("Bye!!!")
                })
        })

        AfterEach(func() {
                if d != nil && d.Db != nil {
                        d.Db.Close()
                }
        })
})

Expected Behavior:

$ ginkgo
Running Suite: foo
==================
Random Seed: 1400479221
Will run 1 of 1 specs

Hello!!!
• Failure [0.009 seconds]
Foo
/home/action/workspace/test/foo_test.go:53
  NewSqliteDatabase()
  /home/action/workspace/test/foo_test.go:46
    opens a sqlite3 database and returns *Database [It]
    /home/action/workspace/test/foo_test.go:45

    Expected
        <*sql.DB | 0xc210070c80>: { ... }
    to be nil

    /home/action/workspace/test/foo_test.go:43
------------------------------

Ran 1 of 1 Specs in 0.018 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestFoo (0.02 seconds)
FAIL

Ginkgo ran in 1.448502789s
Test Suite Failed

Actual Behavior:

$ ginkgo
test: ginkgo
Running Suite: foo
==================
Random Seed: 1400479000
Will run 1 of 1 specs

Hello!!!
^C
Ran 1 of 1 Specs in 29.979 seconds
FAIL! -- 0 Passed | 0 Failed | 0 Pending | 0 Skipped
Ginkgo ran in 31.682427676s
$ go version
go version go1.2.2 linux/amd64
$ ginkgo version
Ginkgo Version 1.0.0-beta
@onsi
Copy link
Owner Author

onsi commented May 24, 2014

It looks like *sql.DB has a deeply nested recursive structure. I've changed the maximum nesting-level that Gomega's formatter will traversed to 10 (it used to be 20 which is crazy high).

This will prevent your test from hanging but will dump a ton of output to screen. I'm going to make the output configurable as part of #37 so you'll be able to control just how much output you get pretty soon.

@onsi onsi closed this as completed May 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant