Skip to content
New issue

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

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

Already on GitHub? # to your account

go test fails with go1.5 #232

Closed
rovaughn opened this issue Aug 25, 2015 · 7 comments
Closed

go test fails with go1.5 #232

rovaughn opened this issue Aug 25, 2015 · 7 comments

Comments

@rovaughn
Copy link

I'm curious if this is happening to anyone else.

I built go1.5 from source, bootstrapping with go1.4. When I run go test -short using go1.5, I get the following output.

--- FAIL: TestPreparedStmt (0.00s)
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:291: Insert: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
    sqltest.go:287: Query: no such table: t
PASS
ok      github.com/mattn/go-sqlite3 16.116s

It works fine when I use go1.4 though.

The failing test is in sqlite3_test/sqltest.go. If I remove the concurrency by changing it like so:

278d277
<   ch := make(chan bool)
280,293c279,283
<       go func() {
<           defer func() {
<               ch <- true
<           }()
<           for j := 0; j < 10; j++ {
<               count := 0
<               if err := sel.QueryRow().Scan(&count); err != nil && err != sql.ErrNoRows {
<                   t.Errorf("Query: %v", err)
<                   return
<               }
<               if _, err := ins.Exec(rand.Intn(100)); err != nil {
<                   t.Errorf("Insert: %v", err)
<                   return
<               }

---
>       for j := 0; j < 10; j++ {
>           count := 0
>           if err := sel.QueryRow().Scan(&count); err != nil && err != sql.ErrNoRows {
>               t.Errorf("Query: %v", err)
>               return
295,298c285,289
<       }()
<   }
<   for i := 0; i < nRuns; i++ {
<       <-ch

---
>           if _, err := ins.Exec(rand.Intn(100)); err != nil {
>               t.Errorf("Insert: %v", err)
>               return
>           }
>       }

It works just fine, which implies it's thread safety related. Perhaps https://golang.org/doc/go1.5#runtime could've affected it?

@rovaughn rovaughn changed the title go test fails with go1.5 go test fails with go1.5 Aug 25, 2015
@rovaughn
Copy link
Author

I just tried running go test -race -short, but it didn't find any problems.

@mattn
Copy link
Owner

mattn commented Aug 28, 2015

did you try in latest go-sqlite3?

@siscia
Copy link

siscia commented Jul 16, 2016

I do have a very similar problem.

If I run go test -short it works and pass everything, however this code doesn't works:

func CreateVirtualQuestions(vDb *sql.DB) (VirtualQuestions, error) {
    errors := make(chan error)

    var vq VirtualQuestions
    vq.connection = vDb

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions ORDER BY RANDOM()`)
        if err != nil {
            log.Print("1")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomQuestions = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE faculty = "medicin" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("2")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomMedicin = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE part = "logic" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("3")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomLogic = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE part = "math" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("4")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomMath = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE part = "biology" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("5")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomBiology = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE part = "chemistry" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("6")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomChemistry = rows
    }()

    go func() {
        rows, err := vDb.Query(`SELECT * FROM questions WHERE part = "physic" ORDER BY RANDOM()`)
        if err != nil {
            log.Print("2")
            log.Fatal(err)
            errors <- err
        }
        vq.RandomPhysic = rows
    }()

    return vq, nil
}

each goroutines runs a query and puts the rows in a structure.

$ go version
go version go1.6 linux/amd64

@mattn
Copy link
Owner

mattn commented Jul 17, 2016

What error did you get on 1.5?

@siscia
Copy link

siscia commented Jul 17, 2016

Sorry, I tried only on the 1.6

The error says it doesn't find the table.

@tscholl2
Copy link

tscholl2 commented Jul 17, 2016

Are you by chance using an in memory (":memory:") database? If so you should see #204

@siscia
Copy link

siscia commented Jul 17, 2016

@tscholl2 yes I am

Thank you :) Fix it :)

gjrtimmer added a commit to gjrtimmer/go-sqlite3 that referenced this issue May 26, 2018
Compile Section Closes mattn#175
Compile Section Closes mattn#201
Compile Section Closes mattn#206
Compile Section Closes mattn#404
Compile Section Closes mattn#217
Compile Section Closes mattn#224
Compile Section Closes mattn#234
Compile Section Closes mattn#242
Feature table Closes mattn#255
Description Section Closes mattn#232
Golang:1.6 not supported Closes mattn#272
Golang:1.5 not supported + compilation section Closes mattn#283
usleep Implemented Closes mattn#285
FAQ Section Closes mattn#289
Compile Section closes mattn#295
FAQ Section Closes mattn#305
PR339 Closes mattn#318 mattn#321
Compilation Section Closes mattn#341
PR407 Closes mattn#364
Feature `sqlite_vtable` Closes mattn#393
Compile Section Closes mattn#416
sqlite_trace feature Closes mattn#433
Compilation Section Closes mattn#435
Compilation Section Closes mattn#443
Golang:1.6 Not Supported Closes mattn#445
Compilation Section Closes mattn#451
Compilation Section Closes mattn#467
Compilation Section Closes mattn#491
Compilation Section Closes mattn#495
Compilation Section Closes mattn#505
Compilation Section Closes mattn#557
Compilation Section Closes mattn#560
@mattn mattn closed this as completed in c9394b1 May 27, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants