Skip to content

Commit

Permalink
Fix ftp batch submission handler, adjust selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 10, 2023
1 parent 308b23a commit 25f3456
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 67 deletions.
43 changes: 20 additions & 23 deletions client/src/utils/navigation/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1032,35 +1032,32 @@ upload:
close: 'div#composite div.upload-buttons button'

selectors:
tab: '#tab-title-link-${tab}'
ftp_add: '#btn-ftp'
ftp_popup: '.upload-ftp-body'
ftp_items: '.upload-ftp-row'
ftp_close: '.popover-header .popover-close'
row: '#upload-row-${n}'
settings_button: '#upload-row-${n} .upload-settings span'
title: '#upload-row-${n} .upload-title'
paste_content: '#upload-row-${n} .upload-text-content'
settings: '.upload-settings-table'
setting_space_to_tab: '.upload-space-to-tab'
setting_deferred: '.upload-deferred'
start: '#activity-upload'
start_uploading: '#btn-start'
create: '#btn-new'
build_btn: '#rule-based #btn-build'
close: '#btn-close'
rule_source_content: 'textarea.upload-rule-source-content'
rule_select_data_type: '.rule-data-type'
create: '#btn-new'
file_dialog: '#btn-remote-files'
file_dialog_ok: '.file-dialog-modal-ok'
file_source_selector:
type: xpath
selector: '//span[contains(@title, "${path}")]'
paste_content: '#upload-row-${n} .upload-text-content'
paste_new: .upload-paste
row: '#upload-row-${n}'
rule_dataset_dialog: '[data-description="rules dataset dialog"]'
rule_dataset_selector:
selector: '.selection-dialog-modal'
rule_dataset_selector_row:
selector: '.selection-dialog-modal [aria-rowindex="${rowindex}"]'
build_btn: '#rule-based #btn-build'
file_source_selector:
type: xpath
selector: '//span[contains(@title, "${path}")]'
file_dialog_ok: '.file-dialog-modal-ok'
paste_new: .upload-paste
rule_select_data_type: '.rule-data-type'
rule_source_content: 'textarea.upload-rule-source-content'
tab: '#tab-title-link-${tab}'
title: '#upload-row-${n} .upload-title'
settings: '.upload-settings-table'
settings_button: '#upload-row-${n} .upload-settings span'
setting_deferred: '.upload-deferred'
setting_space_to_tab: '.upload-space-to-tab'
start: '#activity-upload'
start_uploading: '#btn-start'

new_user_welcome:
selectors:
Expand Down
57 changes: 29 additions & 28 deletions client/src/utils/upload-queue.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/*
galaxy upload utilities - requires FormData and XMLHttpRequest
*/

import axios from "axios";
import { getAppRoot } from "onload/loadConfig";

import { uploadPayload } from "@/utils/upload-payload.js";
import { uploadSubmit } from "@/utils/upload-submit.js";
import { sendPayload, uploadSubmit } from "@/utils/upload-submit.js";

export class UploadQueue {
constructor(options) {
Expand Down Expand Up @@ -72,29 +68,7 @@ export class UploadQueue {
// Initiate upload process
start(ftpBatch = false) {
if (ftpBatch) {
// package ftp files separately, and remove them from queue
const list = [];
Object.entries(this.queue).forEach(([key, model]) => {
if (model.status === "queued" && model.fileMode === "ftp") {
this.queue.remove(model.id);
list.push(this.opts.get(key));
}
});
if (list.length > 0) {
const data = uploadPayload(list, this.opts.historyId);
axios
.post(`${getAppRoot()}api/tools/fetch`, data)
.then((message) => {
list.forEach((model) => {
this.opts.success(model.id, message);
});
})
.catch((message) => {
list.forEach((model) => {
this.opts.error(model.id, message);
});
});
}
this._processFtp();
}
if (!this.isRunning) {
this.isRunning = true;
Expand Down Expand Up @@ -127,6 +101,33 @@ export class UploadQueue {
this._processSubmit(index, data);
}

// Submit remote files as single batch request
_processFtp() {
const list = [];
for (const index of this.queue.keys()) {
const model = this.opts.get(index);
if (model.status === "queued" && model.fileMode === "ftp") {
list.push({ index, ...model });
this.remove(index);
}
}
if (list.length > 0) {
const data = uploadPayload(list, this.opts.historyId);
sendPayload(data, {
success: (message) => {
list.forEach((model) => {
this.opts.success(model.index, message);
});
},
error: (message) => {
list.forEach((model) => {
this.opts.error(model.index, message);
});
},
});
}
}

// Get next item to be processed
_processIndex() {
return this.queue.keys().next().value;
Expand Down
6 changes: 3 additions & 3 deletions client/src/utils/upload-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function buildFingerprint(cnf) {
};
}

function submitPayload(payload, cnf) {
export function sendPayload(payload, cnf) {
axios
.post(`${getAppRoot()}api/tools/fetch`, payload)
.then((response) => {
Expand All @@ -31,7 +31,7 @@ function tusUpload(uploadables, index, data, tusEndpoint, cnf) {
if (!uploadable) {
// We've uploaded all files or blobs; delete files from data and submit fetch payload
delete data["files"];
return submitPayload(data, cnf);
return sendPayload(data, cnf);
}
console.debug(`Starting chunked upload for ${uploadable.name} [chunkSize=${chunkSize}].`);
const upload = new tus.Upload(uploadable, {
Expand Down Expand Up @@ -115,7 +115,7 @@ export function uploadSubmit(config) {
if (data.targets.length && data.targets[0].elements.length) {
const pasted = data.targets[0].elements[0];
if (pasted.src == "url") {
return submitPayload(data, cnf);
return sendPayload(data, cnf);
} else {
const blob = new Blob([pasted.paste_content]);
blob.name = data.targets[0].elements[0].name || "default";
Expand Down
2 changes: 1 addition & 1 deletion test/integration_selenium/test_upload_file_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestPosixFileSourceSeleniumIntegration(PosixFileSourceSetup, SeleniumInteg
def test_upload_from_posix(self):
self.admin_login()
self.components.upload.start.wait_for_and_click()
self.components.upload.ftp_add.wait_for_and_click()
self.components.upload.file_dialog.wait_for_and_click()
self.components.upload.file_source_selector(path="gxfiles://posix_test").wait_for_and_click()
self.components.upload.file_source_selector(path="gxfiles://posix_test/a").wait_for_and_click()
self.components.upload.file_dialog_ok.wait_for_and_click()
Expand Down
25 changes: 13 additions & 12 deletions test/integration_selenium/test_upload_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ def handle_galaxy_config_kwds(cls, config):
def ftp_dir(cls):
return cls.temp_config_dir("ftp")

def _upload_all(self):
def _upload_all(self, n):
self.home()
self.components.upload.start.wait_for_and_click()
self.components.upload.ftp_add.wait_for_and_click()
self.components.upload.ftp_popup.wait_for_visible()
for item in self.components.upload.ftp_items().all():
item.click()
self.components.upload.ftp_close.wait_for_and_click()
self.components.upload.row(n=0).wait_for_visible()
self.components.upload.file_dialog.wait_for_and_click()
self.components.upload.file_source_selector(path="gxftp://").wait_for_and_click()
for i in range(n):
self.components.upload.file_source_selector(path="gxftp://%i.txt" % i).wait_for_and_click()
self.components.upload.file_dialog_ok.wait_for_and_click()
for i in range(n):
self.components.upload.row(n=i).wait_for_visible()
self.upload_start()
self.sleep_for(self.wait_types.UX_RENDER)
self.wait_for_history()
Expand All @@ -43,18 +44,18 @@ def _create_ftp_dir(self):
@selenium_test
def test_upload_simplest(self):
user_ftp_dir = self._create_ftp_dir()
file_path = os.path.join(user_ftp_dir, "1.txt")
file_path = os.path.join(user_ftp_dir, "0.txt")
with open(file_path, "w") as f:
f.write("Hello World!")
self._upload_all()
self._upload_all(1)

@selenium_test
def test_upload_multiple(self):
user_ftp_dir = self._create_ftp_dir()
file_path = os.path.join(user_ftp_dir, "1.txt")
file_path = os.path.join(user_ftp_dir, "0.txt")
with open(file_path, "w") as f:
f.write("Hello World!")
file_path = os.path.join(user_ftp_dir, "2.txt")
file_path = os.path.join(user_ftp_dir, "1.txt")
with open(file_path, "w") as f:
f.write("Hello Galaxy!")
self._upload_all()
self._upload_all(2)

0 comments on commit 25f3456

Please sign in to comment.