test(logging): add back DeleteLog test (#3114)
fixes #1654
To de-flake:
- Instead of calling Logs() which is flakey, we write a new log entry then do a single deletion
- Also verified with BE that the quota for all logadmin api calls is 600/min and 1k/hour
It might still flake for a new reason since DeleteLogs is getting deprecated and may be inherently flakey. I will monitor it.
diff --git a/logging/logging_test.go b/logging/logging_test.go
index 0e511ba..2c5d6d7 100644
--- a/logging/logging_test.go
+++ b/logging/logging_test.go
@@ -473,38 +473,27 @@
}
}
-func TestLogsAndDelete(t *testing.T) {
- t.Skip("https://github.com/googleapis/google-cloud-go/issues/1654")
-
- // This function tests both the Logs and DeleteLog methods. We only try to
- // delete those logs that we can observe and that were generated by this
- // test. This may not include the logs generated from the current test run,
- // because the logging service is only eventually consistent. It's
- // therefore possible that on some runs, this test will do nothing.
+func TestDeleteLog(t *testing.T) {
ctx := context.Background()
- it := aclient.Logs(ctx)
- nDeleted := 0
- for {
- logID, err := it.Next()
- if err == iterator.Done {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
- if strings.HasPrefix(logID, testLogIDPrefix) {
- if err := aclient.DeleteLog(ctx, logID); err != nil {
- // Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find
- // a log that is returned by Logs.
- if status.Code(err) != codes.NotFound {
- t.Fatalf("deleting %q: %v", logID, err)
- }
- } else {
- nDeleted++
- }
- }
+ initLogs()
+ c, a := newClients(ctx, testProjectID)
+ defer c.Close()
+ defer a.Close()
+ lg := c.Logger(testLogID)
+
+ if err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}); err != nil {
+ t.Fatal(err)
}
- t.Logf("deleted %d logs", nDeleted)
+
+ if err := aclient.DeleteLog(ctx, testLogID); err != nil {
+ // Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find
+ // a log that is returned by Logs.
+ if status.Code(err) != codes.NotFound {
+ t.Fatalf("deleting %q: %v", testLogID, err)
+ }
+ } else {
+ t.Logf("deleted log_id: %q", testLogID)
+ }
}
func TestNonProjectParent(t *testing.T) {