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

Count() incorrect for tx rollback. #108

Open
pyrofolium opened this issue Jan 18, 2024 · 0 comments
Open

Count() incorrect for tx rollback. #108

pyrofolium opened this issue Jan 18, 2024 · 0 comments

Comments

@pyrofolium
Copy link

pyrofolium commented Jan 18, 2024

package main_test

import (
	"errors"
	"fmt"
	"log"
	"strconv"
	"testing"

	"github.com/kelindar/column"
	"github.com/zeebo/assert"
)

func TestTransaction(t *testing.T) {
	players := column.NewCollection()
	err := errors.Join(players.CreateColumn("name", column.ForString()),
		players.CreateColumn("class", column.ForString()),
		players.CreateColumn("balance", column.ForFloat64()),
		players.CreateColumn("age", column.ForInt16()))
	if err != nil {
		log.Fatalf("failed to create columns")
	}
	addPlayers := func() {
		err = players.Query(func(tx *column.Txn) error {
			for i := 0; i < 20; i++ {
				_, err := tx.Insert(func(r column.Row) error {
					r.SetString("name", "merlin")
					r.SetString("class", "mage")
					r.SetFloat64("balance", 99.95)
					r.SetInt16("age", 107)
					return nil
				})
				if err != nil {
					return err
				}
			}
			return nil
		})
	}

	addPlayers()
	assert.Nil(t, err)
	assert.Equal(t, players.Count(), 20)

	addPlayersError := func() error {
		err = players.Query(func(tx *column.Txn) error {
			for i := 0; i < 20; i++ {
				_, err = tx.Insert(func(r column.Row) error {
					r.SetString("name", "merlin")
					r.SetString("class", "mage")
					r.SetFloat64("balance", 99.95)
					r.SetInt16("age", 107)
					return nil
				})
				if err != nil {
					return err
				}
			}
			return errors.New("SHOULD NOT PASS")
		})
		return err
	}

	err = addPlayersError()
	assert.Error(t, err)                 //should be error.
	assert.Equal(t, players.Count(), 20) //transaction failed should still be 20.
}

Seems like counts are not accounting for rollbacks. The last transaction should fail, and the count should remain 20 but it doesn't?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant