2023-11-24 11:15:46 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/internal"
|
2024-02-07 11:18:56 +00:00
|
|
|
"github.com/databricks/cli/internal/acc"
|
|
|
|
"github.com/databricks/cli/libs/env"
|
2023-11-24 11:15:46 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/listing"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccLocalStateStaleness(t *testing.T) {
|
2024-02-07 11:18:56 +00:00
|
|
|
ctx, wt := acc.WorkspaceTest(t)
|
|
|
|
w := wt.W
|
2023-11-24 11:15:46 +00:00
|
|
|
|
|
|
|
// The approach for this test is as follows:
|
|
|
|
// 1) First deploy of bundle instance A
|
|
|
|
// 2) First deploy of bundle instance B
|
|
|
|
// 3) Second deploy of bundle instance A
|
|
|
|
// Because of deploy (2), the locally cached state of bundle instance A should be stale.
|
|
|
|
// Then for deploy (3), it must use the remote state over the stale local state.
|
|
|
|
|
2024-02-07 11:18:56 +00:00
|
|
|
nodeTypeId := internal.GetNodeTypeId(env.Get(ctx, "CLOUD_ENV"))
|
2023-11-24 11:15:46 +00:00
|
|
|
uniqueId := uuid.New().String()
|
|
|
|
initialize := func() string {
|
2024-02-07 11:18:56 +00:00
|
|
|
root, err := initTestTemplate(t, ctx, "basic", map[string]any{
|
2023-11-24 11:15:46 +00:00
|
|
|
"unique_id": uniqueId,
|
|
|
|
"node_type_id": nodeTypeId,
|
|
|
|
"spark_version": "13.2.x-snapshot-scala2.12",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
2024-02-07 11:18:56 +00:00
|
|
|
err = destroyBundle(t, ctx, root)
|
2023-11-24 11:15:46 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
return root
|
|
|
|
}
|
|
|
|
|
2024-02-07 11:18:56 +00:00
|
|
|
var err error
|
|
|
|
|
2023-11-24 11:15:46 +00:00
|
|
|
bundleA := initialize()
|
|
|
|
bundleB := initialize()
|
|
|
|
|
|
|
|
// 1) Deploy bundle A
|
2024-02-07 11:18:56 +00:00
|
|
|
err = deployBundle(t, ctx, bundleA)
|
2023-11-24 11:15:46 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// 2) Deploy bundle B
|
2024-02-07 11:18:56 +00:00
|
|
|
err = deployBundle(t, ctx, bundleB)
|
2023-11-24 11:15:46 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// 3) Deploy bundle A again
|
2024-02-07 11:18:56 +00:00
|
|
|
err = deployBundle(t, ctx, bundleA)
|
2023-11-24 11:15:46 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Assert that there is only a single job in the workspace corresponding to this bundle.
|
|
|
|
iter := w.Jobs.List(context.Background(), jobs.ListJobsRequest{
|
|
|
|
Name: "test-job-basic-" + uniqueId,
|
|
|
|
})
|
|
|
|
jobs, err := listing.ToSlice(context.Background(), iter)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, jobs, 1)
|
|
|
|
}
|