Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
srinidhis94 committed Apr 13, 2021
1 parent c996bd2 commit 8ace3bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
4 changes: 2 additions & 2 deletions drivers/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
var (
mySQLNameToTestCase = map[string]TestCase{
"single": {
TableToCreateQueryMap: map[string]string{"": `CREATE TABLE %s (
TableToCreateQueryMap: map[string]string{DefaultTableCreateQueryKey: `CREATE TABLE %s (
id INT(6) UNSIGNED,
firstname VARCHAR(30),
lastname VARCHAR(30),
Expand Down Expand Up @@ -203,7 +203,7 @@ func (MySQL) Describe(table string, db *sql.DB) ([]FieldDescriptor, error) {
}

func (m MySQL) MultiDescribe(tables []string, db *sql.DB) (map[string][]FieldDescriptor, []string, error) {
processedTables := make(map[string]bool)
processedTables := make(map[string]struct{})
tableToDescriptorMap := make(map[string][]FieldDescriptor)
for {
newTableToDescriptorMap, newlyReferencedTables, err := multiDescribeHelper(tables, processedTables, db, m)
Expand Down
4 changes: 2 additions & 2 deletions drivers/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='%s'
var (
pgNameToTestCase = map[string]TestCase{
"single": {
TableToCreateQueryMap: map[string]string{"": CreateTable},
TableToCreateQueryMap: map[string]string{DefaultTableCreateQueryKey: CreateTable},
TableCreationOrder: nil,
},
"multi": {
Expand Down Expand Up @@ -208,7 +208,7 @@ func (p Postgres) MapField(descriptor FieldDescriptor) Field {
}

func (p Postgres) MultiDescribe(tables []string, db *sql.DB) (map[string][]FieldDescriptor, []string, error) {
processedTables := make(map[string]bool)
processedTables := make(map[string]struct{})
tableToDescriptorMap := make(map[string][]FieldDescriptor)
for {
newTableToDescriptorMap, newlyReferencedTables, err := multiDescribeHelper(tables, processedTables, db, p)
Expand Down
16 changes: 9 additions & 7 deletions drivers/sqlcommons.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
"strings"
)

func multiDescribeHelper(tables []string, processedTables map[string]bool, db *sql.DB, d Driver) (map[string][]FieldDescriptor, []string, error) {
const (
DefaultTableCreateQueryKey = ""
)

func multiDescribeHelper(tables []string, processedTables map[string]struct{}, db *sql.DB, d Driver) (map[string][]FieldDescriptor, []string, error) {
knownTables := make(map[string]bool)
tableDescriptorMap := make(map[string][]FieldDescriptor)
var newlyReferencedTables []string
Expand All @@ -25,12 +29,13 @@ func multiDescribeHelper(tables []string, processedTables map[string]bool, db *s
continue
}
foreignTableName := field.ForeignKeyDescriptor.ForeignTableName
if !knownTables[foreignTableName] && !processedTables[foreignTableName] {
if _, ok := processedTables[foreignTableName]; ok && !knownTables[foreignTableName] {
newlyReferencedTables = append(newlyReferencedTables, foreignTableName)
knownTables[foreignTableName] = true
}
}
tableDescriptorMap[table] = fields
processedTables[table] = struct{}{}
}
return tableDescriptorMap, newlyReferencedTables, nil
}
Expand Down Expand Up @@ -63,12 +68,9 @@ func getInsertionOrder(tablesToFieldsMap map[string][]FieldDescriptor) ([]string
}
}
if newInsertCount == 0 {
break
return nil, errors.New("error generating insertion order. Maybe necessary dependencies are not met")
}
}
if len(tablesVisitOrder) < len(tablesToFieldsMap) {
return nil, errors.New("error generating insertion order. Maybe necessary dependencies are not met")
}
return tablesVisitOrder, nil
}

Expand All @@ -78,7 +80,7 @@ func testTable(db *sql.DB, testCase, table string, d Driver) error {
return err
}
if test.TableCreationOrder == nil {
if query, ok := test.TableToCreateQueryMap[""]; ok {
if query, ok := test.TableToCreateQueryMap[DefaultTableCreateQueryKey]; ok {
if res, err := db.ExecContext(context.Background(), fmt.Sprintf(query, table)); err != nil {
return err
} else if _, err := res.RowsAffected(); err != nil {
Expand Down
14 changes: 0 additions & 14 deletions pkg/fuzzer/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ func Run(fields []drivers.FieldDescriptor, f flags.Flags) error {
}
}()
return runHelper(f, action.Insert, []interface{}{db, fields, driver, f.Table})
//numJobs := f.Num
//workers := f.Workers
//jobs := make(chan struct{}, numJobs)
//wg := &sync.WaitGroup{}
//wg.Add(workers)
//for w := 0; w < workers; w++ {
// go worker(jobs, fields, wg, f)
//}
//
//for j := 0; j < numJobs; j++ {
// jobs <- struct{}{}
//}
//close(jobs)
//wg.Wait()
}

func RunMulti(tableToFieldsMap map[string][]drivers.FieldDescriptor, insertionOrder []string, f flags.Flags) error {
Expand Down

0 comments on commit 8ace3bc

Please sign in to comment.