@@ -669,19 +669,18 @@ func Test_MaintainUniqueSources_DeleteOldPartitions(t *testing.T) {
669669 r .NoError (err )
670670
671671 t .Run ("MaintainUniqueSources" , func (_ * testing.T ) {
672- // adds an entry to `admin.all_distinct_dbname_metrics`
672+ // creates an empty metric table and adds
673+ // an entry to `admin.all_distinct_dbname_metrics`
673674 err = pgw .SyncMetric ("test" , "test_metric_1" , AddOp )
674675 r .NoError (err )
675-
676676 var numOfEntries int
677677 err = conn .QueryRow (ctx , "SELECT count(*) FROM admin.all_distinct_dbname_metrics;" ).Scan (& numOfEntries )
678678 a .NoError (err )
679679 a .Equal (1 , numOfEntries )
680680
681681 // manually call the maintenance routine
682682 pgw .MaintainUniqueSources ()
683-
684- // entry should have been deleted, because it has no corresponding entries in `test_metric_1` table.
683+ // entry should have been deleted, because there is now rows in `test_metric_1` table.
685684 err = conn .QueryRow (ctx , "SELECT count(*) FROM admin.all_distinct_dbname_metrics;" ).Scan (& numOfEntries )
686685 a .NoError (err )
687686 a .Equal (0 , numOfEntries )
@@ -696,19 +695,25 @@ func Test_MaintainUniqueSources_DeleteOldPartitions(t *testing.T) {
696695 },
697696 }
698697 pgw .flush (message )
699-
700698 // manually call the maintenance routine
701699 pgw .MaintainUniqueSources ()
702-
703- // entry should have been added, because there is a corresponding entry in `test_metric_1` table just written.
700+ // an entry should have been added, because there is a corresponding entry in `test_metric_1` table just written.
704701 err = conn .QueryRow (ctx , "SELECT count(*) FROM admin.all_distinct_dbname_metrics;" ).Scan (& numOfEntries )
705702 a .NoError (err )
706703 a .Equal (1 , numOfEntries )
707704
705+ message [0 ].DBName = "test_db_2"
706+ pgw .flush (message )
707+ // explicitly use `public.*` prefix.
708+ pgw .sinkDb .Exec (pgw .ctx , "SELECT admin.update_listing_table(metric_table_name => 'public.test_metric_1');" )
709+ // another entry should have been added.
710+ err = conn .QueryRow (ctx , "SELECT count(*) FROM admin.all_distinct_dbname_metrics;" ).Scan (& numOfEntries )
711+ a .NoError (err )
712+ a .Equal (2 , numOfEntries )
713+
708714 _ , err = conn .Exec (ctx , "DROP TABLE test_metric_1;" )
709715 r .NoError (err )
710-
711- // the corresponding entry should be deleted
716+ // all entries should be deleted
712717 pgw .MaintainUniqueSources ()
713718 err = conn .QueryRow (ctx , "SELECT count(*) FROM admin.all_distinct_dbname_metrics;" ).Scan (& numOfEntries )
714719 a .NoError (err )
@@ -730,10 +735,10 @@ func Test_MaintainUniqueSources_DeleteOldPartitions(t *testing.T) {
730735 // create the 3rd level time partition with end bound yesterday
731736 _ , err = conn .Exec (ctx ,
732737 fmt .Sprintf (
733- `CREATE TABLE subpartitions.test_metric_2_dbname_time
738+ `CREATE TABLE subpartitions.test_metric_2_dbname_time
734739 PARTITION OF subpartitions.test_metric_2_dbname
735740 FOR VALUES FROM ('%s') TO ('%s')` ,
736- boundStart , boundEnd ),
741+ boundStart , boundEnd ),
737742 )
738743 a .NoError (err )
739744 _ , err = conn .Exec (ctx , "COMMENT ON TABLE subpartitions.test_metric_2_dbname_time IS $$pgwatch-generated-metric-dbname-time-lvl$$" )
0 commit comments